{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f46ca4b3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前操作系统: Windows\n",
      "字体设置: ['SimHei']\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import scipy.stats as stats\n",
    "import scipy\n",
    "from datetime import datetime\n",
    "import statsmodels.formula.api as smf\n",
    "\n",
    "from matplotlib import style\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.dates as mdates\n",
    "from matplotlib.font_manager import FontProperties\n",
    "from pylab import mpl\n",
    "import platform\n",
    "\n",
    "# 根据操作系统设置中文字体\n",
    "system = platform.system()\n",
    "if system == 'Windows':\n",
    "    plt.rcParams['font.sans-serif'] = ['SimHei']  # Windows使用黑体\n",
    "    plt.rcParams['axes.unicode_minus'] = False  # 解决负号显示问题\n",
    "elif system == 'Darwin':  # macOS\n",
    "    plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']  # macOS使用Arial Unicode MS\n",
    "    plt.rcParams['axes.unicode_minus'] = False\n",
    "else:  # Linux\n",
    "    plt.rcParams['font.sans-serif'] = ['WenQuanYi Micro Hei']  # Linux使用文泉驿微米黑\n",
    "    plt.rcParams['axes.unicode_minus'] = False\n",
    "\n",
    "# 输出矢量图\n",
    "%matplotlib inline\n",
    "%config InlineBackend.figure_format = 'svg'\n",
    "\n",
    "from IPython.core.interactiveshell import InteractiveShell\n",
    "InteractiveShell.ast_node_interactivity = 'all'\n",
    "\n",
    "# 设置pandas显示选项\n",
    "pd.set_option('display.max_columns', None)\n",
    "\n",
    "print(f\"当前操作系统: {system}\")\n",
    "print(f\"字体设置: {plt.rcParams['font.sans-serif']}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e28500bb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>Trdmnt</th>\n",
       "      <th>Opndt</th>\n",
       "      <th>Mopnprc</th>\n",
       "      <th>Clsdt</th>\n",
       "      <th>Mclsprc</th>\n",
       "      <th>Mnshrtrd</th>\n",
       "      <th>Mnvaltrd</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>Ndaytrd</th>\n",
       "      <th>Return</th>\n",
       "      <th>Mretnd</th>\n",
       "      <th>Markettype</th>\n",
       "      <th>Capchgdt</th>\n",
       "      <th>Ahshrtrd_M</th>\n",
       "      <th>Ahvaltrd_M</th>\n",
       "      <th>month</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>list_month</th>\n",
       "      <th>ret</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-04</td>\n",
       "      <td>3</td>\n",
       "      <td>49.00</td>\n",
       "      <td>30</td>\n",
       "      <td>43.68</td>\n",
       "      <td>13400</td>\n",
       "      <td>6.150000e+05</td>\n",
       "      <td>1.157520e+09</td>\n",
       "      <td>2.118487e+09</td>\n",
       "      <td>20</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4</td>\n",
       "      <td>1991-04-03</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1991-04-30</td>\n",
       "      <td>0.006651</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-05</td>\n",
       "      <td>2</td>\n",
       "      <td>43.46</td>\n",
       "      <td>31</td>\n",
       "      <td>38.34</td>\n",
       "      <td>187800</td>\n",
       "      <td>7.675000e+06</td>\n",
       "      <td>1.016010e+09</td>\n",
       "      <td>1.859497e+09</td>\n",
       "      <td>24</td>\n",
       "      <td>-0.122253</td>\n",
       "      <td>0.235714</td>\n",
       "      <td>4</td>\n",
       "      <td>1991-04-03</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1991-05-31</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>2</td>\n",
       "      <td>-0.128345</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-06</td>\n",
       "      <td>1</td>\n",
       "      <td>38.53</td>\n",
       "      <td>28</td>\n",
       "      <td>33.99</td>\n",
       "      <td>30600</td>\n",
       "      <td>1.094000e+06</td>\n",
       "      <td>9.007350e+08</td>\n",
       "      <td>1.648521e+09</td>\n",
       "      <td>23</td>\n",
       "      <td>-0.113459</td>\n",
       "      <td>-0.113459</td>\n",
       "      <td>4</td>\n",
       "      <td>1991-04-03</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1991-06-30</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>3</td>\n",
       "      <td>-0.119551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-07</td>\n",
       "      <td>1</td>\n",
       "      <td>33.65</td>\n",
       "      <td>31</td>\n",
       "      <td>29.54</td>\n",
       "      <td>6100</td>\n",
       "      <td>1.940430e+05</td>\n",
       "      <td>7.828100e+08</td>\n",
       "      <td>1.432695e+09</td>\n",
       "      <td>16</td>\n",
       "      <td>-0.130921</td>\n",
       "      <td>-0.130921</td>\n",
       "      <td>4</td>\n",
       "      <td>1991-04-03</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1991-07-31</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>4</td>\n",
       "      <td>-0.137013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-08</td>\n",
       "      <td>1</td>\n",
       "      <td>29.39</td>\n",
       "      <td>31</td>\n",
       "      <td>15.00</td>\n",
       "      <td>3243100</td>\n",
       "      <td>4.957624e+07</td>\n",
       "      <td>6.748338e+08</td>\n",
       "      <td>1.346275e+09</td>\n",
       "      <td>15</td>\n",
       "      <td>-0.411588</td>\n",
       "      <td>-0.411587</td>\n",
       "      <td>4</td>\n",
       "      <td>1991-08-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1991-08-31</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>5</td>\n",
       "      <td>-0.417680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>886908</th>\n",
       "      <td>920992</td>\n",
       "      <td>2025-05</td>\n",
       "      <td>6</td>\n",
       "      <td>20.00</td>\n",
       "      <td>30</td>\n",
       "      <td>20.46</td>\n",
       "      <td>92609592</td>\n",
       "      <td>1.922463e+09</td>\n",
       "      <td>5.707967e+08</td>\n",
       "      <td>1.979115e+09</td>\n",
       "      <td>19</td>\n",
       "      <td>0.051312</td>\n",
       "      <td>0.051715</td>\n",
       "      <td>64</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2025-05-31</td>\n",
       "      <td>NaN</td>\n",
       "      <td>32</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>886909</th>\n",
       "      <td>920992</td>\n",
       "      <td>2025-06</td>\n",
       "      <td>3</td>\n",
       "      <td>20.40</td>\n",
       "      <td>30</td>\n",
       "      <td>21.26</td>\n",
       "      <td>73152031</td>\n",
       "      <td>1.580767e+09</td>\n",
       "      <td>5.931152e+08</td>\n",
       "      <td>2.056500e+09</td>\n",
       "      <td>20</td>\n",
       "      <td>0.039101</td>\n",
       "      <td>0.039101</td>\n",
       "      <td>64</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2025-06-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>33</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>886910</th>\n",
       "      <td>920992</td>\n",
       "      <td>2025-07</td>\n",
       "      <td>1</td>\n",
       "      <td>21.13</td>\n",
       "      <td>31</td>\n",
       "      <td>22.44</td>\n",
       "      <td>96064221</td>\n",
       "      <td>2.126994e+09</td>\n",
       "      <td>6.260351e+08</td>\n",
       "      <td>2.170642e+09</td>\n",
       "      <td>23</td>\n",
       "      <td>0.055503</td>\n",
       "      <td>0.055503</td>\n",
       "      <td>64</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2025-07-31</td>\n",
       "      <td>NaN</td>\n",
       "      <td>34</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>886911</th>\n",
       "      <td>920992</td>\n",
       "      <td>2025-08</td>\n",
       "      <td>1</td>\n",
       "      <td>22.12</td>\n",
       "      <td>29</td>\n",
       "      <td>21.65</td>\n",
       "      <td>63953451</td>\n",
       "      <td>1.432608e+09</td>\n",
       "      <td>6.039955e+08</td>\n",
       "      <td>2.094225e+09</td>\n",
       "      <td>21</td>\n",
       "      <td>-0.035205</td>\n",
       "      <td>-0.035205</td>\n",
       "      <td>64</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2025-08-31</td>\n",
       "      <td>NaN</td>\n",
       "      <td>35</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>886912</th>\n",
       "      <td>920992</td>\n",
       "      <td>2025-09</td>\n",
       "      <td>1</td>\n",
       "      <td>21.75</td>\n",
       "      <td>30</td>\n",
       "      <td>21.07</td>\n",
       "      <td>83403669</td>\n",
       "      <td>1.981091e+09</td>\n",
       "      <td>5.878146e+08</td>\n",
       "      <td>2.038121e+09</td>\n",
       "      <td>22</td>\n",
       "      <td>-0.026790</td>\n",
       "      <td>-0.026790</td>\n",
       "      <td>64</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2025-09-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>36</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>886913 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Stkcd   Trdmnt  Opndt  Mopnprc  Clsdt  Mclsprc  Mnshrtrd  \\\n",
       "0       000001  1991-04      3    49.00     30    43.68     13400   \n",
       "1       000001  1991-05      2    43.46     31    38.34    187800   \n",
       "2       000001  1991-06      1    38.53     28    33.99     30600   \n",
       "3       000001  1991-07      1    33.65     31    29.54      6100   \n",
       "4       000001  1991-08      1    29.39     31    15.00   3243100   \n",
       "...        ...      ...    ...      ...    ...      ...       ...   \n",
       "886908  920992  2025-05      6    20.00     30    20.46  92609592   \n",
       "886909  920992  2025-06      3    20.40     30    21.26  73152031   \n",
       "886910  920992  2025-07      1    21.13     31    22.44  96064221   \n",
       "886911  920992  2025-08      1    22.12     29    21.65  63953451   \n",
       "886912  920992  2025-09      1    21.75     30    21.07  83403669   \n",
       "\n",
       "            Mnvaltrd  floatingvalue    totalvalue  Ndaytrd    Return  \\\n",
       "0       6.150000e+05   1.157520e+09  2.118487e+09       20       NaN   \n",
       "1       7.675000e+06   1.016010e+09  1.859497e+09       24 -0.122253   \n",
       "2       1.094000e+06   9.007350e+08  1.648521e+09       23 -0.113459   \n",
       "3       1.940430e+05   7.828100e+08  1.432695e+09       16 -0.130921   \n",
       "4       4.957624e+07   6.748338e+08  1.346275e+09       15 -0.411588   \n",
       "...              ...            ...           ...      ...       ...   \n",
       "886908  1.922463e+09   5.707967e+08  1.979115e+09       19  0.051312   \n",
       "886909  1.580767e+09   5.931152e+08  2.056500e+09       20  0.039101   \n",
       "886910  2.126994e+09   6.260351e+08  2.170642e+09       23  0.055503   \n",
       "886911  1.432608e+09   6.039955e+08  2.094225e+09       21 -0.035205   \n",
       "886912  1.981091e+09   5.878146e+08  2.038121e+09       22 -0.026790   \n",
       "\n",
       "          Mretnd  Markettype    Capchgdt  Ahshrtrd_M  Ahvaltrd_M      month  \\\n",
       "0            NaN           4  1991-04-03         NaN         NaN 1991-04-30   \n",
       "1       0.235714           4  1991-04-03         NaN         NaN 1991-05-31   \n",
       "2      -0.113459           4  1991-04-03         NaN         NaN 1991-06-30   \n",
       "3      -0.130921           4  1991-04-03         NaN         NaN 1991-07-31   \n",
       "4      -0.411587           4  1991-08-01         NaN         NaN 1991-08-31   \n",
       "...          ...         ...         ...         ...         ...        ...   \n",
       "886908  0.051715          64  2023-04-25         0.0         0.0 2025-05-31   \n",
       "886909  0.039101          64  2023-04-25         0.0         0.0 2025-06-30   \n",
       "886910  0.055503          64  2023-04-25         0.0         0.0 2025-07-31   \n",
       "886911 -0.035205          64  2023-04-25         0.0         0.0 2025-08-31   \n",
       "886912 -0.026790          64  2023-04-25         0.0         0.0 2025-09-30   \n",
       "\n",
       "         rfmonth  list_month       ret  \n",
       "0       0.006651           1       NaN  \n",
       "1       0.006092           2 -0.128345  \n",
       "2       0.006092           3 -0.119551  \n",
       "3       0.006092           4 -0.137013  \n",
       "4       0.006092           5 -0.417680  \n",
       "...          ...         ...       ...  \n",
       "886908       NaN          32       NaN  \n",
       "886909       NaN          33       NaN  \n",
       "886910       NaN          34       NaN  \n",
       "886911       NaN          35       NaN  \n",
       "886912       NaN          36       NaN  \n",
       "\n",
       "[886913 rows x 21 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cross = pd.read_csv('D:/笃行楼209/TRD_Mnth202509.csv')\n",
    "from pandas.tseries.offsets import MonthEnd\n",
    "# 处理月份格式\n",
    "cross['month'] = pd.to_datetime(cross['Trdmnt'], format='%Y-%m') + MonthEnd(1)\n",
    "# 补齐股票代码 如果不满6位 在前面补上0\n",
    "cross['Stkcd'] = cross['Stkcd'].apply(lambda x: '{:0>6}'.format(x)) # 6位股票代码\n",
    "# 重命名列以匹配后续代码\n",
    "cross.rename(columns={'Mretwd': 'Return', 'Msmvosd': 'floatingvalue', 'Msmvttl': 'totalvalue'}, inplace=True)\n",
    "\n",
    "# 导入无风险利率数据\n",
    "rf_data = pd.read_csv('D:/笃行楼209/Marketret_mon_stock2024.csv')\n",
    "# 处理月份格式\n",
    "rf_data['month'] = pd.to_datetime(rf_data['month'], format='%b %Y') + MonthEnd(1)\n",
    "# 只保留需要的列\n",
    "rf_data = rf_data[['month', 'rfmonth']]\n",
    "\n",
    "# 合并无风险利率到cross\n",
    "cross = pd.merge(cross, rf_data, on='month', how='left')\n",
    "\n",
    "# 添加一个序列 用来统计公司上市的第几个月\n",
    "cross = cross.sort_values(by=['Stkcd', 'month'])\n",
    "cross['list_month'] = cross.groupby('Stkcd').cumcount() + 1\n",
    "\n",
    "# 计算超额收益率\n",
    "cross['ret'] = cross['Return'] - cross['rfmonth']\n",
    "cross['floatingvalue'] = cross['floatingvalue'] * 1000\n",
    "cross['totalvalue'] = cross['totalvalue'] * 1000\n",
    "\n",
    "cross"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f45b216a",
   "metadata": {},
   "source": [
    "生成下一个月的收益率"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43579a5b",
   "metadata": {},
   "source": [
    "方法1：补全所有个股的日期序列，再使用shift"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "baf30250",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "方法1完成：补全日期序列后使用shift\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>Trdmnt</th>\n",
       "      <th>Opndt</th>\n",
       "      <th>Mopnprc</th>\n",
       "      <th>Clsdt</th>\n",
       "      <th>Mclsprc</th>\n",
       "      <th>Mnshrtrd</th>\n",
       "      <th>Mnvaltrd</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>Ndaytrd</th>\n",
       "      <th>Return</th>\n",
       "      <th>Mretnd</th>\n",
       "      <th>Markettype</th>\n",
       "      <th>Capchgdt</th>\n",
       "      <th>Ahshrtrd_M</th>\n",
       "      <th>Ahvaltrd_M</th>\n",
       "      <th>month</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>list_month</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>Cumsum_tradingday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-01</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.50</td>\n",
       "      <td>27.0</td>\n",
       "      <td>10.54</td>\n",
       "      <td>17488100.0</td>\n",
       "      <td>1.867690e+08</td>\n",
       "      <td>3.134297e+09</td>\n",
       "      <td>4.543463e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-01-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>46.0</td>\n",
       "      <td>-0.002994</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>247.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-02</td>\n",
       "      <td>13.0</td>\n",
       "      <td>10.60</td>\n",
       "      <td>28.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>8544200.0</td>\n",
       "      <td>9.192790e+07</td>\n",
       "      <td>3.161060e+09</td>\n",
       "      <td>4.582260e+09</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-02-28</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>47.0</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>244.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-03</td>\n",
       "      <td>1.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>31.0</td>\n",
       "      <td>10.76</td>\n",
       "      <td>18810600.0</td>\n",
       "      <td>2.059094e+08</td>\n",
       "      <td>3.199719e+09</td>\n",
       "      <td>4.638299e+09</td>\n",
       "      <td>23.0</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-03-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>244.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-04</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.78</td>\n",
       "      <td>28.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>13235500.0</td>\n",
       "      <td>1.380604e+08</td>\n",
       "      <td>2.881531e+09</td>\n",
       "      <td>4.177055e+09</td>\n",
       "      <td>20.0</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-04-30</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>49.0</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>243.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-05</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>31.0</td>\n",
       "      <td>9.80</td>\n",
       "      <td>53197900.0</td>\n",
       "      <td>6.049730e+08</td>\n",
       "      <td>2.914242e+09</td>\n",
       "      <td>4.224473e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-05-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>-0.073005</td>\n",
       "      <td>244.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2453228</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-08</td>\n",
       "      <td>1.0</td>\n",
       "      <td>8.50</td>\n",
       "      <td>30.0</td>\n",
       "      <td>8.19</td>\n",
       "      <td>14436632.0</td>\n",
       "      <td>1.185912e+08</td>\n",
       "      <td>2.284861e+08</td>\n",
       "      <td>7.922264e+08</td>\n",
       "      <td>22.0</td>\n",
       "      <td>-0.037603</td>\n",
       "      <td>-0.037603</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-08-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>23.0</td>\n",
       "      <td>-0.038721</td>\n",
       "      <td>0.276049</td>\n",
       "      <td>242.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2453229</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-09</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.15</td>\n",
       "      <td>30.0</td>\n",
       "      <td>10.46</td>\n",
       "      <td>18109819.0</td>\n",
       "      <td>1.566140e+08</td>\n",
       "      <td>2.918149e+08</td>\n",
       "      <td>1.011806e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.277167</td>\n",
       "      <td>0.277167</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-09-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>24.0</td>\n",
       "      <td>0.276049</td>\n",
       "      <td>0.389895</td>\n",
       "      <td>241.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2453230</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-10</td>\n",
       "      <td>8.0</td>\n",
       "      <td>13.02</td>\n",
       "      <td>31.0</td>\n",
       "      <td>14.55</td>\n",
       "      <td>86774237.0</td>\n",
       "      <td>1.145494e+09</td>\n",
       "      <td>4.059185e+08</td>\n",
       "      <td>1.407435e+09</td>\n",
       "      <td>18.0</td>\n",
       "      <td>0.391013</td>\n",
       "      <td>0.391013</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-10-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>25.0</td>\n",
       "      <td>0.389895</td>\n",
       "      <td>0.241494</td>\n",
       "      <td>242.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2453231</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-11</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14.69</td>\n",
       "      <td>29.0</td>\n",
       "      <td>18.08</td>\n",
       "      <td>130783392.0</td>\n",
       "      <td>2.346534e+09</td>\n",
       "      <td>5.043990e+08</td>\n",
       "      <td>1.748895e+09</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.242612</td>\n",
       "      <td>0.242612</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-11-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0.241494</td>\n",
       "      <td>-0.243928</td>\n",
       "      <td>241.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2453232</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-12</td>\n",
       "      <td>2.0</td>\n",
       "      <td>18.41</td>\n",
       "      <td>31.0</td>\n",
       "      <td>13.69</td>\n",
       "      <td>87260377.0</td>\n",
       "      <td>1.426585e+09</td>\n",
       "      <td>3.819260e+08</td>\n",
       "      <td>1.324246e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>-0.242810</td>\n",
       "      <td>-0.242810</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-12-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>27.0</td>\n",
       "      <td>-0.243928</td>\n",
       "      <td>NaN</td>\n",
       "      <td>242.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2112840 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          Stkcd   Trdmnt  Opndt  Mopnprc  Clsdt  Mclsprc     Mnshrtrd  \\\n",
       "49       000001  1995-01    3.0    10.50   27.0    10.54   17488100.0   \n",
       "50       000001  1995-02   13.0    10.60   28.0    10.63    8544200.0   \n",
       "51       000001  1995-03    1.0    10.63   31.0    10.76   18810600.0   \n",
       "52       000001  1995-04    3.0    10.78   28.0     9.69   13235500.0   \n",
       "53       000001  1995-05    2.0     9.69   31.0     9.80   53197900.0   \n",
       "...         ...      ...    ...      ...    ...      ...          ...   \n",
       "2453228  920992  2024-08    1.0     8.50   30.0     8.19   14436632.0   \n",
       "2453229  920992  2024-09    2.0     8.15   30.0    10.46   18109819.0   \n",
       "2453230  920992  2024-10    8.0    13.02   31.0    14.55   86774237.0   \n",
       "2453231  920992  2024-11    1.0    14.69   29.0    18.08  130783392.0   \n",
       "2453232  920992  2024-12    2.0    18.41   31.0    13.69   87260377.0   \n",
       "\n",
       "             Mnvaltrd  floatingvalue    totalvalue  Ndaytrd    Return  \\\n",
       "49       1.867690e+08   3.134297e+09  4.543463e+09     19.0  0.005725   \n",
       "50       9.192790e+07   3.161060e+09  4.582260e+09     12.0  0.008539   \n",
       "51       2.059094e+08   3.199719e+09  4.638299e+09     23.0  0.012230   \n",
       "52       1.380604e+08   2.881531e+09  4.177055e+09     20.0 -0.099442   \n",
       "53       6.049730e+08   2.914242e+09  4.224473e+09     22.0  0.011352   \n",
       "...               ...            ...           ...      ...       ...   \n",
       "2453228  1.185912e+08   2.284861e+08  7.922264e+08     22.0 -0.037603   \n",
       "2453229  1.566140e+08   2.918149e+08  1.011806e+09     19.0  0.277167   \n",
       "2453230  1.145494e+09   4.059185e+08  1.407435e+09     18.0  0.391013   \n",
       "2453231  2.346534e+09   5.043990e+08  1.748895e+09     21.0  0.242612   \n",
       "2453232  1.426585e+09   3.819260e+08  1.324246e+09     22.0 -0.242810   \n",
       "\n",
       "           Mretnd  Markettype    Capchgdt  Ahshrtrd_M  Ahvaltrd_M      month  \\\n",
       "49       0.005725         4.0  1994-09-02         NaN         NaN 1995-01-31   \n",
       "50       0.008539         4.0  1994-09-02         NaN         NaN 1995-02-28   \n",
       "51       0.012230         4.0  1994-09-02         NaN         NaN 1995-03-31   \n",
       "52      -0.099442         4.0  1994-09-02         NaN         NaN 1995-04-30   \n",
       "53       0.011352         4.0  1994-09-02         NaN         NaN 1995-05-31   \n",
       "...           ...         ...         ...         ...         ...        ...   \n",
       "2453228 -0.037603        64.0  2023-04-25         0.0         0.0 2024-08-31   \n",
       "2453229  0.277167        64.0  2023-04-25         0.0         0.0 2024-09-30   \n",
       "2453230  0.391013        64.0  2023-04-25         0.0         0.0 2024-10-31   \n",
       "2453231  0.242612        64.0  2023-04-25         0.0         0.0 2024-11-30   \n",
       "2453232 -0.242810        64.0  2023-04-25         0.0         0.0 2024-12-31   \n",
       "\n",
       "          rfmonth  list_month       ret  next_ret  Cumsum_tradingday  \n",
       "49       0.008719        46.0 -0.002994 -0.000180              247.0  \n",
       "50       0.008719        47.0 -0.000180  0.003511              244.0  \n",
       "51       0.008719        48.0  0.003511 -0.108161              244.0  \n",
       "52       0.008719        49.0 -0.108161  0.002633              243.0  \n",
       "53       0.008719        50.0  0.002633 -0.073005              244.0  \n",
       "...           ...         ...       ...       ...                ...  \n",
       "2453228  0.001118        23.0 -0.038721  0.276049              242.0  \n",
       "2453229  0.001118        24.0  0.276049  0.389895              241.0  \n",
       "2453230  0.001118        25.0  0.389895  0.241494              242.0  \n",
       "2453231  0.001118        26.0  0.241494 -0.243928              241.0  \n",
       "2453232  0.001118        27.0 -0.243928       NaN              242.0  \n",
       "\n",
       "[2112840 rows x 23 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建所有日期和股票代码的完整组合\n",
    "all_months = pd.DataFrame(cross['month'].unique(), columns=['month'])\n",
    "all_stocks = pd.DataFrame(cross['Stkcd'].unique(), columns=['Stkcd'])\n",
    "# 创建笛卡尔积 - 所有股票和所有月份的组合\n",
    "full_index = all_stocks.merge(all_months, how='cross')\n",
    "\n",
    "# 将原始数据合并到完整索引中\n",
    "cross_full = full_index.merge(cross, on=['Stkcd', 'month'], how='left')\n",
    "# 按股票代码和月份排序\n",
    "cross_full = cross_full.sort_values(['Stkcd', 'month'])\n",
    "# 使用shift生成下月收益率\n",
    "cross_full['next_ret'] = cross_full.groupby('Stkcd')['ret'].shift(-1)\n",
    "\n",
    "# 只保留原始数据存在的行\n",
    "cross = cross.merge(cross_full[['Stkcd', 'month', 'next_ret']], \n",
    "                    on=['Stkcd', 'month'], how='right')\n",
    "\n",
    "# 添加一个变量 用来统计过去一年的交易日数量之和\n",
    "cross['Cumsum_tradingday'] = cross.groupby('Stkcd')['Ndaytrd'].transform(lambda x: x.rolling(window=12, min_periods=1).sum())\n",
    "print(\"方法1完成：补全日期序列后使用shift\")\n",
    "\n",
    "cross = cross[(cross['month'] >= '1995-01-31') & (cross['month'] <= '2024-12-31')]\n",
    "cross"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8398fb55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MarketR</th>\n",
       "      <th>MarketR_e</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>MKT</th>\n",
       "      <th>ret_e</th>\n",
       "      <th>marketret3</th>\n",
       "      <th>marketret6</th>\n",
       "      <th>marketret12</th>\n",
       "      <th>Q</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1991-01-31</th>\n",
       "      <td>0.029998</td>\n",
       "      <td>0.036554</td>\n",
       "      <td>0.006930</td>\n",
       "      <td>0.023068</td>\n",
       "      <td>0.029624</td>\n",
       "      <td>-0.084127</td>\n",
       "      <td>-0.305662</td>\n",
       "      <td>0.254049</td>\n",
       "      <td>1991 Q1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-02-28</th>\n",
       "      <td>0.010203</td>\n",
       "      <td>0.021860</td>\n",
       "      <td>0.006930</td>\n",
       "      <td>0.003273</td>\n",
       "      <td>0.014930</td>\n",
       "      <td>-0.183573</td>\n",
       "      <td>-0.384745</td>\n",
       "      <td>0.241492</td>\n",
       "      <td>1991 Q1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-03-31</th>\n",
       "      <td>-0.099663</td>\n",
       "      <td>-0.060425</td>\n",
       "      <td>0.006930</td>\n",
       "      <td>-0.106593</td>\n",
       "      <td>-0.067355</td>\n",
       "      <td>-0.252928</td>\n",
       "      <td>-0.445049</td>\n",
       "      <td>0.288857</td>\n",
       "      <td>1991 Q1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-04-30</th>\n",
       "      <td>-0.079652</td>\n",
       "      <td>-0.031449</td>\n",
       "      <td>0.006651</td>\n",
       "      <td>-0.086303</td>\n",
       "      <td>-0.038100</td>\n",
       "      <td>-0.234776</td>\n",
       "      <td>-0.394937</td>\n",
       "      <td>0.691749</td>\n",
       "      <td>1991 Q2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-05-31</th>\n",
       "      <td>-0.074521</td>\n",
       "      <td>0.005375</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.080613</td>\n",
       "      <td>-0.000717</td>\n",
       "      <td>-0.236294</td>\n",
       "      <td>0.181673</td>\n",
       "      <td>1.542701</td>\n",
       "      <td>1991 Q2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-08-31</th>\n",
       "      <td>-0.031468</td>\n",
       "      <td>-0.033685</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>-0.032586</td>\n",
       "      <td>-0.034803</td>\n",
       "      <td>0.151050</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024 Q3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-30</th>\n",
       "      <td>0.195992</td>\n",
       "      <td>0.227078</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>0.194874</td>\n",
       "      <td>0.225960</td>\n",
       "      <td>0.200147</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024 Q3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-10-31</th>\n",
       "      <td>-0.003409</td>\n",
       "      <td>0.070220</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>-0.004527</td>\n",
       "      <td>0.069102</td>\n",
       "      <td>0.000228</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024 Q4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-11-30</th>\n",
       "      <td>0.009724</td>\n",
       "      <td>0.045312</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>0.008606</td>\n",
       "      <td>0.044194</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024 Q4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-12-31</th>\n",
       "      <td>-0.002679</td>\n",
       "      <td>-0.040799</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>-0.003797</td>\n",
       "      <td>-0.041917</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024 Q4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>408 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             MarketR  MarketR_e   rfmonth       MKT     ret_e  marketret3  \\\n",
       "month                                                                       \n",
       "1991-01-31  0.029998   0.036554  0.006930  0.023068  0.029624   -0.084127   \n",
       "1991-02-28  0.010203   0.021860  0.006930  0.003273  0.014930   -0.183573   \n",
       "1991-03-31 -0.099663  -0.060425  0.006930 -0.106593 -0.067355   -0.252928   \n",
       "1991-04-30 -0.079652  -0.031449  0.006651 -0.086303 -0.038100   -0.234776   \n",
       "1991-05-31 -0.074521   0.005375  0.006092 -0.080613 -0.000717   -0.236294   \n",
       "...              ...        ...       ...       ...       ...         ...   \n",
       "2024-08-31 -0.031468  -0.033685  0.001118 -0.032586 -0.034803    0.151050   \n",
       "2024-09-30  0.195992   0.227078  0.001118  0.194874  0.225960    0.200147   \n",
       "2024-10-31 -0.003409   0.070220  0.001118 -0.004527  0.069102    0.000228   \n",
       "2024-11-30  0.009724   0.045312  0.001118  0.008606  0.044194         NaN   \n",
       "2024-12-31 -0.002679  -0.040799  0.001118 -0.003797 -0.041917         NaN   \n",
       "\n",
       "            marketret6  marketret12        Q  \n",
       "month                                         \n",
       "1991-01-31   -0.305662     0.254049  1991 Q1  \n",
       "1991-02-28   -0.384745     0.241492  1991 Q1  \n",
       "1991-03-31   -0.445049     0.288857  1991 Q1  \n",
       "1991-04-30   -0.394937     0.691749  1991 Q2  \n",
       "1991-05-31    0.181673     1.542701  1991 Q2  \n",
       "...                ...          ...      ...  \n",
       "2024-08-31         NaN          NaN  2024 Q3  \n",
       "2024-09-30         NaN          NaN  2024 Q3  \n",
       "2024-10-31         NaN          NaN  2024 Q4  \n",
       "2024-11-30         NaN          NaN  2024 Q4  \n",
       "2024-12-31         NaN          NaN  2024 Q4  \n",
       "\n",
       "[408 rows x 9 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pandas.tseries.offsets import MonthEnd # 月末\n",
    "Market_ret = pd.read_csv('D:/笃行楼209/Marketret_mon_stock2024.csv')\n",
    "Market_ret['month'] = pd.to_datetime(Market_ret['month'], format='%b %Y') + MonthEnd(0)\n",
    "Market_ret.set_index('month', inplace=True)\n",
    "Market_ret.sort_index(inplace=True)\n",
    "Market_ret = Market_ret.drop(columns=['Unnamed: 0'])\n",
    "Market_ret.rename(columns={'ret': 'MKT'}, inplace=True)\n",
    "Market_ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6f0dfc80",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>Trdmnt</th>\n",
       "      <th>Opndt</th>\n",
       "      <th>Mopnprc</th>\n",
       "      <th>Clsdt</th>\n",
       "      <th>Mclsprc</th>\n",
       "      <th>Mnshrtrd</th>\n",
       "      <th>Mnvaltrd</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>Ndaytrd</th>\n",
       "      <th>Return</th>\n",
       "      <th>Mretnd</th>\n",
       "      <th>Markettype</th>\n",
       "      <th>Capchgdt</th>\n",
       "      <th>Ahshrtrd_M</th>\n",
       "      <th>Ahvaltrd_M</th>\n",
       "      <th>month</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>list_month</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>Cumsum_tradingday</th>\n",
       "      <th>MKT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-01</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.50</td>\n",
       "      <td>27.0</td>\n",
       "      <td>10.54</td>\n",
       "      <td>17488100.0</td>\n",
       "      <td>1.867690e+08</td>\n",
       "      <td>3.134297e+09</td>\n",
       "      <td>4.543463e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-01-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>46.0</td>\n",
       "      <td>-0.002994</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>247.0</td>\n",
       "      <td>-0.125017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-02</td>\n",
       "      <td>13.0</td>\n",
       "      <td>10.60</td>\n",
       "      <td>28.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>8544200.0</td>\n",
       "      <td>9.192790e+07</td>\n",
       "      <td>3.161060e+09</td>\n",
       "      <td>4.582260e+09</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-02-28</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>47.0</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>244.0</td>\n",
       "      <td>-0.022778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-03</td>\n",
       "      <td>1.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>31.0</td>\n",
       "      <td>10.76</td>\n",
       "      <td>18810600.0</td>\n",
       "      <td>2.059094e+08</td>\n",
       "      <td>3.199719e+09</td>\n",
       "      <td>4.638299e+09</td>\n",
       "      <td>23.0</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-03-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>244.0</td>\n",
       "      <td>0.122163</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-04</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.78</td>\n",
       "      <td>28.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>13235500.0</td>\n",
       "      <td>1.380604e+08</td>\n",
       "      <td>2.881531e+09</td>\n",
       "      <td>4.177055e+09</td>\n",
       "      <td>20.0</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-04-30</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>49.0</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>243.0</td>\n",
       "      <td>-0.113023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-05</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>31.0</td>\n",
       "      <td>9.80</td>\n",
       "      <td>53197900.0</td>\n",
       "      <td>6.049730e+08</td>\n",
       "      <td>2.914242e+09</td>\n",
       "      <td>4.224473e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-05-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>-0.073005</td>\n",
       "      <td>244.0</td>\n",
       "      <td>0.166736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112835</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-08</td>\n",
       "      <td>1.0</td>\n",
       "      <td>8.50</td>\n",
       "      <td>30.0</td>\n",
       "      <td>8.19</td>\n",
       "      <td>14436632.0</td>\n",
       "      <td>1.185912e+08</td>\n",
       "      <td>2.284861e+08</td>\n",
       "      <td>7.922264e+08</td>\n",
       "      <td>22.0</td>\n",
       "      <td>-0.037603</td>\n",
       "      <td>-0.037603</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-08-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>23.0</td>\n",
       "      <td>-0.038721</td>\n",
       "      <td>0.276049</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.032586</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112836</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-09</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.15</td>\n",
       "      <td>30.0</td>\n",
       "      <td>10.46</td>\n",
       "      <td>18109819.0</td>\n",
       "      <td>1.566140e+08</td>\n",
       "      <td>2.918149e+08</td>\n",
       "      <td>1.011806e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.277167</td>\n",
       "      <td>0.277167</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-09-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>24.0</td>\n",
       "      <td>0.276049</td>\n",
       "      <td>0.389895</td>\n",
       "      <td>241.0</td>\n",
       "      <td>0.194874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112837</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-10</td>\n",
       "      <td>8.0</td>\n",
       "      <td>13.02</td>\n",
       "      <td>31.0</td>\n",
       "      <td>14.55</td>\n",
       "      <td>86774237.0</td>\n",
       "      <td>1.145494e+09</td>\n",
       "      <td>4.059185e+08</td>\n",
       "      <td>1.407435e+09</td>\n",
       "      <td>18.0</td>\n",
       "      <td>0.391013</td>\n",
       "      <td>0.391013</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-10-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>25.0</td>\n",
       "      <td>0.389895</td>\n",
       "      <td>0.241494</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.004527</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112838</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-11</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14.69</td>\n",
       "      <td>29.0</td>\n",
       "      <td>18.08</td>\n",
       "      <td>130783392.0</td>\n",
       "      <td>2.346534e+09</td>\n",
       "      <td>5.043990e+08</td>\n",
       "      <td>1.748895e+09</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.242612</td>\n",
       "      <td>0.242612</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-11-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0.241494</td>\n",
       "      <td>-0.243928</td>\n",
       "      <td>241.0</td>\n",
       "      <td>0.008606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112839</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-12</td>\n",
       "      <td>2.0</td>\n",
       "      <td>18.41</td>\n",
       "      <td>31.0</td>\n",
       "      <td>13.69</td>\n",
       "      <td>87260377.0</td>\n",
       "      <td>1.426585e+09</td>\n",
       "      <td>3.819260e+08</td>\n",
       "      <td>1.324246e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>-0.242810</td>\n",
       "      <td>-0.242810</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-12-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>27.0</td>\n",
       "      <td>-0.243928</td>\n",
       "      <td>NaN</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.003797</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2112840 rows × 24 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          Stkcd   Trdmnt  Opndt  Mopnprc  Clsdt  Mclsprc     Mnshrtrd  \\\n",
       "0        000001  1995-01    3.0    10.50   27.0    10.54   17488100.0   \n",
       "1        000001  1995-02   13.0    10.60   28.0    10.63    8544200.0   \n",
       "2        000001  1995-03    1.0    10.63   31.0    10.76   18810600.0   \n",
       "3        000001  1995-04    3.0    10.78   28.0     9.69   13235500.0   \n",
       "4        000001  1995-05    2.0     9.69   31.0     9.80   53197900.0   \n",
       "...         ...      ...    ...      ...    ...      ...          ...   \n",
       "2112835  920992  2024-08    1.0     8.50   30.0     8.19   14436632.0   \n",
       "2112836  920992  2024-09    2.0     8.15   30.0    10.46   18109819.0   \n",
       "2112837  920992  2024-10    8.0    13.02   31.0    14.55   86774237.0   \n",
       "2112838  920992  2024-11    1.0    14.69   29.0    18.08  130783392.0   \n",
       "2112839  920992  2024-12    2.0    18.41   31.0    13.69   87260377.0   \n",
       "\n",
       "             Mnvaltrd  floatingvalue    totalvalue  Ndaytrd    Return  \\\n",
       "0        1.867690e+08   3.134297e+09  4.543463e+09     19.0  0.005725   \n",
       "1        9.192790e+07   3.161060e+09  4.582260e+09     12.0  0.008539   \n",
       "2        2.059094e+08   3.199719e+09  4.638299e+09     23.0  0.012230   \n",
       "3        1.380604e+08   2.881531e+09  4.177055e+09     20.0 -0.099442   \n",
       "4        6.049730e+08   2.914242e+09  4.224473e+09     22.0  0.011352   \n",
       "...               ...            ...           ...      ...       ...   \n",
       "2112835  1.185912e+08   2.284861e+08  7.922264e+08     22.0 -0.037603   \n",
       "2112836  1.566140e+08   2.918149e+08  1.011806e+09     19.0  0.277167   \n",
       "2112837  1.145494e+09   4.059185e+08  1.407435e+09     18.0  0.391013   \n",
       "2112838  2.346534e+09   5.043990e+08  1.748895e+09     21.0  0.242612   \n",
       "2112839  1.426585e+09   3.819260e+08  1.324246e+09     22.0 -0.242810   \n",
       "\n",
       "           Mretnd  Markettype    Capchgdt  Ahshrtrd_M  Ahvaltrd_M      month  \\\n",
       "0        0.005725         4.0  1994-09-02         NaN         NaN 1995-01-31   \n",
       "1        0.008539         4.0  1994-09-02         NaN         NaN 1995-02-28   \n",
       "2        0.012230         4.0  1994-09-02         NaN         NaN 1995-03-31   \n",
       "3       -0.099442         4.0  1994-09-02         NaN         NaN 1995-04-30   \n",
       "4        0.011352         4.0  1994-09-02         NaN         NaN 1995-05-31   \n",
       "...           ...         ...         ...         ...         ...        ...   \n",
       "2112835 -0.037603        64.0  2023-04-25         0.0         0.0 2024-08-31   \n",
       "2112836  0.277167        64.0  2023-04-25         0.0         0.0 2024-09-30   \n",
       "2112837  0.391013        64.0  2023-04-25         0.0         0.0 2024-10-31   \n",
       "2112838  0.242612        64.0  2023-04-25         0.0         0.0 2024-11-30   \n",
       "2112839 -0.242810        64.0  2023-04-25         0.0         0.0 2024-12-31   \n",
       "\n",
       "          rfmonth  list_month       ret  next_ret  Cumsum_tradingday       MKT  \n",
       "0        0.008719        46.0 -0.002994 -0.000180              247.0 -0.125017  \n",
       "1        0.008719        47.0 -0.000180  0.003511              244.0 -0.022778  \n",
       "2        0.008719        48.0  0.003511 -0.108161              244.0  0.122163  \n",
       "3        0.008719        49.0 -0.108161  0.002633              243.0 -0.113023  \n",
       "4        0.008719        50.0  0.002633 -0.073005              244.0  0.166736  \n",
       "...           ...         ...       ...       ...                ...       ...  \n",
       "2112835  0.001118        23.0 -0.038721  0.276049              242.0 -0.032586  \n",
       "2112836  0.001118        24.0  0.276049  0.389895              241.0  0.194874  \n",
       "2112837  0.001118        25.0  0.389895  0.241494              242.0 -0.004527  \n",
       "2112838  0.001118        26.0  0.241494 -0.243928              241.0  0.008606  \n",
       "2112839  0.001118        27.0 -0.243928       NaN              242.0 -0.003797  \n",
       "\n",
       "[2112840 rows x 24 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cross = pd.merge(cross,Market_ret[['MKT']],left_on='month',right_on='month',how='left')\n",
    "cross"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca633261",
   "metadata": {},
   "source": [
    "导入价值数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8e28f535",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>month</th>\n",
       "      <th>ep</th>\n",
       "      <th>ep_recent</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-04-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-05-31</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-06-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-07-31</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-08-31</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>809599</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-08-31</td>\n",
       "      <td>0.079184</td>\n",
       "      <td>0.046498</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>809600</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-09-30</td>\n",
       "      <td>0.071525</td>\n",
       "      <td>0.042001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>809601</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-10-31</td>\n",
       "      <td>0.077932</td>\n",
       "      <td>0.063816</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>809602</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-11-30</td>\n",
       "      <td>0.072171</td>\n",
       "      <td>0.059100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>809603</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-12-31</td>\n",
       "      <td>0.073125</td>\n",
       "      <td>0.059881</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>809604 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Stkcd      month        ep  ep_recent\n",
       "0       000001 1991-04-30       NaN        NaN\n",
       "1       000001 1991-05-31       NaN        NaN\n",
       "2       000001 1991-06-30       NaN        NaN\n",
       "3       000001 1991-07-31       NaN        NaN\n",
       "4       000001 1991-08-31       NaN        NaN\n",
       "...        ...        ...       ...        ...\n",
       "809599  605599 2024-08-31  0.079184   0.046498\n",
       "809600  605599 2024-09-30  0.071525   0.042001\n",
       "809601  605599 2024-10-31  0.077932   0.063816\n",
       "809602  605599 2024-11-30  0.072171   0.059100\n",
       "809603  605599 2024-12-31  0.073125   0.059881\n",
       "\n",
       "[809604 rows x 4 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 重新读取EP数据并转换month列\n",
    "EP = pd.read_csv('D:/笃行楼209/EP_individual_mon2024.csv')\n",
    "EP['Stkcd'] = EP['Stkcd'].apply(lambda x: '{:0>6}'.format(x))\n",
    "\n",
    "# 转换month列为日期格式\n",
    "# 根据数据规律: 1991.250000 -> 1991年3月, 1991.333333 -> 1991年4月\n",
    "# 小数部分 = (month - 1) / 12, 所以 month = round(小数部分 * 12) + 1\n",
    "EP['year'] = EP['month'].astype(int)\n",
    "EP['month_decimal'] = EP['month'] - EP['year']\n",
    "EP['month_num'] = (EP['month_decimal'] * 12).round().astype(int) + 1\n",
    "# 处理边界情况\n",
    "EP.loc[EP['month_num'] > 12, 'year'] += 1\n",
    "EP.loc[EP['month_num'] > 12, 'month_num'] -= 12\n",
    "EP['month'] = pd.to_datetime(EP['year'].astype(str) + '-' + EP['month_num'].astype(str) + '-01')\n",
    "EP = EP.drop(['year', 'month_decimal', 'month_num'], axis=1)\n",
    "EP['month'] = EP['month'] + MonthEnd(1)\n",
    "EP = EP[['Stkcd', 'month', 'ep', 'ep_recent']]\n",
    "EP"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c60a383f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>Trdmnt</th>\n",
       "      <th>Opndt</th>\n",
       "      <th>Mopnprc</th>\n",
       "      <th>Clsdt</th>\n",
       "      <th>Mclsprc</th>\n",
       "      <th>Mnshrtrd</th>\n",
       "      <th>Mnvaltrd</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>Ndaytrd</th>\n",
       "      <th>Return</th>\n",
       "      <th>Mretnd</th>\n",
       "      <th>Markettype</th>\n",
       "      <th>Capchgdt</th>\n",
       "      <th>Ahshrtrd_M</th>\n",
       "      <th>Ahvaltrd_M</th>\n",
       "      <th>month</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>list_month</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>Cumsum_tradingday</th>\n",
       "      <th>MKT</th>\n",
       "      <th>ep</th>\n",
       "      <th>ep_recent</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-01</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.50</td>\n",
       "      <td>27.0</td>\n",
       "      <td>10.54</td>\n",
       "      <td>17488100.0</td>\n",
       "      <td>1.867690e+08</td>\n",
       "      <td>3.134297e+09</td>\n",
       "      <td>4.543463e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-01-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>46.0</td>\n",
       "      <td>-0.002994</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>247.0</td>\n",
       "      <td>-0.125017</td>\n",
       "      <td>0.078427</td>\n",
       "      <td>0.078427</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-02</td>\n",
       "      <td>13.0</td>\n",
       "      <td>10.60</td>\n",
       "      <td>28.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>8544200.0</td>\n",
       "      <td>9.192790e+07</td>\n",
       "      <td>3.161060e+09</td>\n",
       "      <td>4.582260e+09</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-02-28</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>47.0</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>244.0</td>\n",
       "      <td>-0.022778</td>\n",
       "      <td>0.077763</td>\n",
       "      <td>0.077763</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-03</td>\n",
       "      <td>1.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>31.0</td>\n",
       "      <td>10.76</td>\n",
       "      <td>18810600.0</td>\n",
       "      <td>2.059094e+08</td>\n",
       "      <td>3.199719e+09</td>\n",
       "      <td>4.638299e+09</td>\n",
       "      <td>23.0</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-03-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>244.0</td>\n",
       "      <td>0.122163</td>\n",
       "      <td>0.076823</td>\n",
       "      <td>0.076823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-04</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.78</td>\n",
       "      <td>28.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>13235500.0</td>\n",
       "      <td>1.380604e+08</td>\n",
       "      <td>2.881531e+09</td>\n",
       "      <td>4.177055e+09</td>\n",
       "      <td>20.0</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-04-30</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>49.0</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>243.0</td>\n",
       "      <td>-0.113023</td>\n",
       "      <td>0.085306</td>\n",
       "      <td>0.085306</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-05</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>31.0</td>\n",
       "      <td>9.80</td>\n",
       "      <td>53197900.0</td>\n",
       "      <td>6.049730e+08</td>\n",
       "      <td>2.914242e+09</td>\n",
       "      <td>4.224473e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-05-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>-0.073005</td>\n",
       "      <td>244.0</td>\n",
       "      <td>0.166736</td>\n",
       "      <td>0.084349</td>\n",
       "      <td>0.084349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112835</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-08</td>\n",
       "      <td>1.0</td>\n",
       "      <td>8.50</td>\n",
       "      <td>30.0</td>\n",
       "      <td>8.19</td>\n",
       "      <td>14436632.0</td>\n",
       "      <td>1.185912e+08</td>\n",
       "      <td>2.284861e+08</td>\n",
       "      <td>7.922264e+08</td>\n",
       "      <td>22.0</td>\n",
       "      <td>-0.037603</td>\n",
       "      <td>-0.037603</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-08-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>23.0</td>\n",
       "      <td>-0.038721</td>\n",
       "      <td>0.276049</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.032586</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112836</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-09</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.15</td>\n",
       "      <td>30.0</td>\n",
       "      <td>10.46</td>\n",
       "      <td>18109819.0</td>\n",
       "      <td>1.566140e+08</td>\n",
       "      <td>2.918149e+08</td>\n",
       "      <td>1.011806e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.277167</td>\n",
       "      <td>0.277167</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-09-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>24.0</td>\n",
       "      <td>0.276049</td>\n",
       "      <td>0.389895</td>\n",
       "      <td>241.0</td>\n",
       "      <td>0.194874</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112837</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-10</td>\n",
       "      <td>8.0</td>\n",
       "      <td>13.02</td>\n",
       "      <td>31.0</td>\n",
       "      <td>14.55</td>\n",
       "      <td>86774237.0</td>\n",
       "      <td>1.145494e+09</td>\n",
       "      <td>4.059185e+08</td>\n",
       "      <td>1.407435e+09</td>\n",
       "      <td>18.0</td>\n",
       "      <td>0.391013</td>\n",
       "      <td>0.391013</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-10-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>25.0</td>\n",
       "      <td>0.389895</td>\n",
       "      <td>0.241494</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.004527</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112838</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-11</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14.69</td>\n",
       "      <td>29.0</td>\n",
       "      <td>18.08</td>\n",
       "      <td>130783392.0</td>\n",
       "      <td>2.346534e+09</td>\n",
       "      <td>5.043990e+08</td>\n",
       "      <td>1.748895e+09</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.242612</td>\n",
       "      <td>0.242612</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-11-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0.241494</td>\n",
       "      <td>-0.243928</td>\n",
       "      <td>241.0</td>\n",
       "      <td>0.008606</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112839</th>\n",
       "      <td>920992</td>\n",
       "      <td>2024-12</td>\n",
       "      <td>2.0</td>\n",
       "      <td>18.41</td>\n",
       "      <td>31.0</td>\n",
       "      <td>13.69</td>\n",
       "      <td>87260377.0</td>\n",
       "      <td>1.426585e+09</td>\n",
       "      <td>3.819260e+08</td>\n",
       "      <td>1.324246e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>-0.242810</td>\n",
       "      <td>-0.242810</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-04-25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-12-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>27.0</td>\n",
       "      <td>-0.243928</td>\n",
       "      <td>NaN</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.003797</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2112840 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          Stkcd   Trdmnt  Opndt  Mopnprc  Clsdt  Mclsprc     Mnshrtrd  \\\n",
       "0        000001  1995-01    3.0    10.50   27.0    10.54   17488100.0   \n",
       "1        000001  1995-02   13.0    10.60   28.0    10.63    8544200.0   \n",
       "2        000001  1995-03    1.0    10.63   31.0    10.76   18810600.0   \n",
       "3        000001  1995-04    3.0    10.78   28.0     9.69   13235500.0   \n",
       "4        000001  1995-05    2.0     9.69   31.0     9.80   53197900.0   \n",
       "...         ...      ...    ...      ...    ...      ...          ...   \n",
       "2112835  920992  2024-08    1.0     8.50   30.0     8.19   14436632.0   \n",
       "2112836  920992  2024-09    2.0     8.15   30.0    10.46   18109819.0   \n",
       "2112837  920992  2024-10    8.0    13.02   31.0    14.55   86774237.0   \n",
       "2112838  920992  2024-11    1.0    14.69   29.0    18.08  130783392.0   \n",
       "2112839  920992  2024-12    2.0    18.41   31.0    13.69   87260377.0   \n",
       "\n",
       "             Mnvaltrd  floatingvalue    totalvalue  Ndaytrd    Return  \\\n",
       "0        1.867690e+08   3.134297e+09  4.543463e+09     19.0  0.005725   \n",
       "1        9.192790e+07   3.161060e+09  4.582260e+09     12.0  0.008539   \n",
       "2        2.059094e+08   3.199719e+09  4.638299e+09     23.0  0.012230   \n",
       "3        1.380604e+08   2.881531e+09  4.177055e+09     20.0 -0.099442   \n",
       "4        6.049730e+08   2.914242e+09  4.224473e+09     22.0  0.011352   \n",
       "...               ...            ...           ...      ...       ...   \n",
       "2112835  1.185912e+08   2.284861e+08  7.922264e+08     22.0 -0.037603   \n",
       "2112836  1.566140e+08   2.918149e+08  1.011806e+09     19.0  0.277167   \n",
       "2112837  1.145494e+09   4.059185e+08  1.407435e+09     18.0  0.391013   \n",
       "2112838  2.346534e+09   5.043990e+08  1.748895e+09     21.0  0.242612   \n",
       "2112839  1.426585e+09   3.819260e+08  1.324246e+09     22.0 -0.242810   \n",
       "\n",
       "           Mretnd  Markettype    Capchgdt  Ahshrtrd_M  Ahvaltrd_M      month  \\\n",
       "0        0.005725         4.0  1994-09-02         NaN         NaN 1995-01-31   \n",
       "1        0.008539         4.0  1994-09-02         NaN         NaN 1995-02-28   \n",
       "2        0.012230         4.0  1994-09-02         NaN         NaN 1995-03-31   \n",
       "3       -0.099442         4.0  1994-09-02         NaN         NaN 1995-04-30   \n",
       "4        0.011352         4.0  1994-09-02         NaN         NaN 1995-05-31   \n",
       "...           ...         ...         ...         ...         ...        ...   \n",
       "2112835 -0.037603        64.0  2023-04-25         0.0         0.0 2024-08-31   \n",
       "2112836  0.277167        64.0  2023-04-25         0.0         0.0 2024-09-30   \n",
       "2112837  0.391013        64.0  2023-04-25         0.0         0.0 2024-10-31   \n",
       "2112838  0.242612        64.0  2023-04-25         0.0         0.0 2024-11-30   \n",
       "2112839 -0.242810        64.0  2023-04-25         0.0         0.0 2024-12-31   \n",
       "\n",
       "          rfmonth  list_month       ret  next_ret  Cumsum_tradingday  \\\n",
       "0        0.008719        46.0 -0.002994 -0.000180              247.0   \n",
       "1        0.008719        47.0 -0.000180  0.003511              244.0   \n",
       "2        0.008719        48.0  0.003511 -0.108161              244.0   \n",
       "3        0.008719        49.0 -0.108161  0.002633              243.0   \n",
       "4        0.008719        50.0  0.002633 -0.073005              244.0   \n",
       "...           ...         ...       ...       ...                ...   \n",
       "2112835  0.001118        23.0 -0.038721  0.276049              242.0   \n",
       "2112836  0.001118        24.0  0.276049  0.389895              241.0   \n",
       "2112837  0.001118        25.0  0.389895  0.241494              242.0   \n",
       "2112838  0.001118        26.0  0.241494 -0.243928              241.0   \n",
       "2112839  0.001118        27.0 -0.243928       NaN              242.0   \n",
       "\n",
       "              MKT        ep  ep_recent  \n",
       "0       -0.125017  0.078427   0.078427  \n",
       "1       -0.022778  0.077763   0.077763  \n",
       "2        0.122163  0.076823   0.076823  \n",
       "3       -0.113023  0.085306   0.085306  \n",
       "4        0.166736  0.084349   0.084349  \n",
       "...           ...       ...        ...  \n",
       "2112835 -0.032586       NaN        NaN  \n",
       "2112836  0.194874       NaN        NaN  \n",
       "2112837 -0.004527       NaN        NaN  \n",
       "2112838  0.008606       NaN        NaN  \n",
       "2112839 -0.003797       NaN        NaN  \n",
       "\n",
       "[2112840 rows x 26 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cross = pd.merge(cross,EP[['Stkcd','month','ep','ep_recent']],on=['Stkcd','month'],how='left')\n",
    "cross"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ea980497",
   "metadata": {},
   "source": [
    "删除30%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "948b704b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fenweishu_guimo</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1995-01-31</th>\n",
       "      <td>3.958033e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-02-28</th>\n",
       "      <td>3.907805e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-03-31</th>\n",
       "      <td>4.341120e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-04-30</th>\n",
       "      <td>3.835094e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-05-31</th>\n",
       "      <td>4.590161e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-08-31</th>\n",
       "      <td>2.442662e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-30</th>\n",
       "      <td>3.012217e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-10-31</th>\n",
       "      <td>3.234660e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-11-30</th>\n",
       "      <td>3.392681e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-12-31</th>\n",
       "      <td>3.176529e+09</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>360 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            fenweishu_guimo\n",
       "month                      \n",
       "1995-01-31     3.958033e+08\n",
       "1995-02-28     3.907805e+08\n",
       "1995-03-31     4.341120e+08\n",
       "1995-04-30     3.835094e+08\n",
       "1995-05-31     4.590161e+08\n",
       "...                     ...\n",
       "2024-08-31     2.442662e+09\n",
       "2024-09-30     3.012217e+09\n",
       "2024-10-31     3.234660e+09\n",
       "2024-11-30     3.392681e+09\n",
       "2024-12-31     3.176529e+09\n",
       "\n",
       "[360 rows x 1 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fenweishu = pd.DataFrame(\n",
    "    cross.groupby(['month'])['totalvalue'].quantile(0.3))\n",
    "fenweishu.columns = ['fenweishu_guimo']\n",
    "fenweishu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3a88bfba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>Trdmnt</th>\n",
       "      <th>Opndt</th>\n",
       "      <th>Mopnprc</th>\n",
       "      <th>Clsdt</th>\n",
       "      <th>Mclsprc</th>\n",
       "      <th>Mnshrtrd</th>\n",
       "      <th>Mnvaltrd</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>Ndaytrd</th>\n",
       "      <th>Return</th>\n",
       "      <th>Mretnd</th>\n",
       "      <th>Markettype</th>\n",
       "      <th>Capchgdt</th>\n",
       "      <th>Ahshrtrd_M</th>\n",
       "      <th>Ahvaltrd_M</th>\n",
       "      <th>month</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>list_month</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>Cumsum_tradingday</th>\n",
       "      <th>MKT</th>\n",
       "      <th>ep</th>\n",
       "      <th>ep_recent</th>\n",
       "      <th>fenweishu_guimo</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-01</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.50</td>\n",
       "      <td>27.0</td>\n",
       "      <td>10.54</td>\n",
       "      <td>17488100.0</td>\n",
       "      <td>1.867690e+08</td>\n",
       "      <td>3.134297e+09</td>\n",
       "      <td>4.543463e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-01-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>46.0</td>\n",
       "      <td>-0.002994</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>247.0</td>\n",
       "      <td>-0.125017</td>\n",
       "      <td>0.078427</td>\n",
       "      <td>0.078427</td>\n",
       "      <td>3.958033e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-02</td>\n",
       "      <td>13.0</td>\n",
       "      <td>10.60</td>\n",
       "      <td>28.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>8544200.0</td>\n",
       "      <td>9.192790e+07</td>\n",
       "      <td>3.161060e+09</td>\n",
       "      <td>4.582260e+09</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-02-28</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>47.0</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>244.0</td>\n",
       "      <td>-0.022778</td>\n",
       "      <td>0.077763</td>\n",
       "      <td>0.077763</td>\n",
       "      <td>3.907805e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-03</td>\n",
       "      <td>1.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>31.0</td>\n",
       "      <td>10.76</td>\n",
       "      <td>18810600.0</td>\n",
       "      <td>2.059094e+08</td>\n",
       "      <td>3.199719e+09</td>\n",
       "      <td>4.638299e+09</td>\n",
       "      <td>23.0</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-03-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>244.0</td>\n",
       "      <td>0.122163</td>\n",
       "      <td>0.076823</td>\n",
       "      <td>0.076823</td>\n",
       "      <td>4.341120e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-04</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.78</td>\n",
       "      <td>28.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>13235500.0</td>\n",
       "      <td>1.380604e+08</td>\n",
       "      <td>2.881531e+09</td>\n",
       "      <td>4.177055e+09</td>\n",
       "      <td>20.0</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-04-30</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>49.0</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>243.0</td>\n",
       "      <td>-0.113023</td>\n",
       "      <td>0.085306</td>\n",
       "      <td>0.085306</td>\n",
       "      <td>3.835094e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-05</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>31.0</td>\n",
       "      <td>9.80</td>\n",
       "      <td>53197900.0</td>\n",
       "      <td>6.049730e+08</td>\n",
       "      <td>2.914242e+09</td>\n",
       "      <td>4.224473e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-05-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>-0.073005</td>\n",
       "      <td>244.0</td>\n",
       "      <td>0.166736</td>\n",
       "      <td>0.084349</td>\n",
       "      <td>0.084349</td>\n",
       "      <td>4.590161e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112451</th>\n",
       "      <td>920985</td>\n",
       "      <td>2022-08</td>\n",
       "      <td>8.0</td>\n",
       "      <td>11.05</td>\n",
       "      <td>31.0</td>\n",
       "      <td>11.43</td>\n",
       "      <td>245414411.0</td>\n",
       "      <td>3.490897e+09</td>\n",
       "      <td>1.352501e+09</td>\n",
       "      <td>3.445035e+09</td>\n",
       "      <td>18.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2022-08-08</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2022-08-31</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.124667</td>\n",
       "      <td>18.0</td>\n",
       "      <td>-0.020875</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.370444e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112452</th>\n",
       "      <td>920985</td>\n",
       "      <td>2022-09</td>\n",
       "      <td>1.0</td>\n",
       "      <td>11.60</td>\n",
       "      <td>30.0</td>\n",
       "      <td>10.02</td>\n",
       "      <td>69513984.0</td>\n",
       "      <td>7.992666e+08</td>\n",
       "      <td>1.185657e+09</td>\n",
       "      <td>3.100952e+09</td>\n",
       "      <td>21.0</td>\n",
       "      <td>-0.123360</td>\n",
       "      <td>-0.123360</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2022-09-06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2022-09-30</td>\n",
       "      <td>0.001307</td>\n",
       "      <td>2.0</td>\n",
       "      <td>-0.124667</td>\n",
       "      <td>0.025581</td>\n",
       "      <td>39.0</td>\n",
       "      <td>-0.065953</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.024944e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112453</th>\n",
       "      <td>920985</td>\n",
       "      <td>2022-10</td>\n",
       "      <td>10.0</td>\n",
       "      <td>10.06</td>\n",
       "      <td>31.0</td>\n",
       "      <td>10.29</td>\n",
       "      <td>33100688.0</td>\n",
       "      <td>3.486847e+08</td>\n",
       "      <td>1.217606e+09</td>\n",
       "      <td>3.184510e+09</td>\n",
       "      <td>16.0</td>\n",
       "      <td>0.026946</td>\n",
       "      <td>0.026946</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2022-09-06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2022-10-31</td>\n",
       "      <td>0.001365</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.025581</td>\n",
       "      <td>-0.014970</td>\n",
       "      <td>55.0</td>\n",
       "      <td>-0.042599</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.165959e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112477</th>\n",
       "      <td>920985</td>\n",
       "      <td>2024-10</td>\n",
       "      <td>8.0</td>\n",
       "      <td>8.60</td>\n",
       "      <td>31.0</td>\n",
       "      <td>15.31</td>\n",
       "      <td>486954437.0</td>\n",
       "      <td>5.439326e+09</td>\n",
       "      <td>2.058722e+09</td>\n",
       "      <td>4.738081e+09</td>\n",
       "      <td>18.0</td>\n",
       "      <td>1.261448</td>\n",
       "      <td>1.261448</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-02-22</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-10-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>27.0</td>\n",
       "      <td>1.260330</td>\n",
       "      <td>-0.157878</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.004527</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.234660e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2112478</th>\n",
       "      <td>920985</td>\n",
       "      <td>2024-11</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14.36</td>\n",
       "      <td>29.0</td>\n",
       "      <td>12.91</td>\n",
       "      <td>363415462.0</td>\n",
       "      <td>5.514141e+09</td>\n",
       "      <td>1.735996e+09</td>\n",
       "      <td>3.995338e+09</td>\n",
       "      <td>21.0</td>\n",
       "      <td>-0.156760</td>\n",
       "      <td>-0.156760</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2023-02-22</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-11-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>28.0</td>\n",
       "      <td>-0.157878</td>\n",
       "      <td>-0.226525</td>\n",
       "      <td>241.0</td>\n",
       "      <td>0.008606</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.392681e+09</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>581929 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          Stkcd   Trdmnt  Opndt  Mopnprc  Clsdt  Mclsprc     Mnshrtrd  \\\n",
       "0        000001  1995-01    3.0    10.50   27.0    10.54   17488100.0   \n",
       "1        000001  1995-02   13.0    10.60   28.0    10.63    8544200.0   \n",
       "2        000001  1995-03    1.0    10.63   31.0    10.76   18810600.0   \n",
       "3        000001  1995-04    3.0    10.78   28.0     9.69   13235500.0   \n",
       "4        000001  1995-05    2.0     9.69   31.0     9.80   53197900.0   \n",
       "...         ...      ...    ...      ...    ...      ...          ...   \n",
       "2112451  920985  2022-08    8.0    11.05   31.0    11.43  245414411.0   \n",
       "2112452  920985  2022-09    1.0    11.60   30.0    10.02   69513984.0   \n",
       "2112453  920985  2022-10   10.0    10.06   31.0    10.29   33100688.0   \n",
       "2112477  920985  2024-10    8.0     8.60   31.0    15.31  486954437.0   \n",
       "2112478  920985  2024-11    1.0    14.36   29.0    12.91  363415462.0   \n",
       "\n",
       "             Mnvaltrd  floatingvalue    totalvalue  Ndaytrd    Return  \\\n",
       "0        1.867690e+08   3.134297e+09  4.543463e+09     19.0  0.005725   \n",
       "1        9.192790e+07   3.161060e+09  4.582260e+09     12.0  0.008539   \n",
       "2        2.059094e+08   3.199719e+09  4.638299e+09     23.0  0.012230   \n",
       "3        1.380604e+08   2.881531e+09  4.177055e+09     20.0 -0.099442   \n",
       "4        6.049730e+08   2.914242e+09  4.224473e+09     22.0  0.011352   \n",
       "...               ...            ...           ...      ...       ...   \n",
       "2112451  3.490897e+09   1.352501e+09  3.445035e+09     18.0       NaN   \n",
       "2112452  7.992666e+08   1.185657e+09  3.100952e+09     21.0 -0.123360   \n",
       "2112453  3.486847e+08   1.217606e+09  3.184510e+09     16.0  0.026946   \n",
       "2112477  5.439326e+09   2.058722e+09  4.738081e+09     18.0  1.261448   \n",
       "2112478  5.514141e+09   1.735996e+09  3.995338e+09     21.0 -0.156760   \n",
       "\n",
       "           Mretnd  Markettype    Capchgdt  Ahshrtrd_M  Ahvaltrd_M      month  \\\n",
       "0        0.005725         4.0  1994-09-02         NaN         NaN 1995-01-31   \n",
       "1        0.008539         4.0  1994-09-02         NaN         NaN 1995-02-28   \n",
       "2        0.012230         4.0  1994-09-02         NaN         NaN 1995-03-31   \n",
       "3       -0.099442         4.0  1994-09-02         NaN         NaN 1995-04-30   \n",
       "4        0.011352         4.0  1994-09-02         NaN         NaN 1995-05-31   \n",
       "...           ...         ...         ...         ...         ...        ...   \n",
       "2112451       NaN        64.0  2022-08-08         0.0         0.0 2022-08-31   \n",
       "2112452 -0.123360        64.0  2022-09-06         0.0         0.0 2022-09-30   \n",
       "2112453  0.026946        64.0  2022-09-06         0.0         0.0 2022-10-31   \n",
       "2112477  1.261448        64.0  2023-02-22         0.0         0.0 2024-10-31   \n",
       "2112478 -0.156760        64.0  2023-02-22         0.0         0.0 2024-11-30   \n",
       "\n",
       "          rfmonth  list_month       ret  next_ret  Cumsum_tradingday  \\\n",
       "0        0.008719        46.0 -0.002994 -0.000180              247.0   \n",
       "1        0.008719        47.0 -0.000180  0.003511              244.0   \n",
       "2        0.008719        48.0  0.003511 -0.108161              244.0   \n",
       "3        0.008719        49.0 -0.108161  0.002633              243.0   \n",
       "4        0.008719        50.0  0.002633 -0.073005              244.0   \n",
       "...           ...         ...       ...       ...                ...   \n",
       "2112451  0.001241         1.0       NaN -0.124667               18.0   \n",
       "2112452  0.001307         2.0 -0.124667  0.025581               39.0   \n",
       "2112453  0.001365         3.0  0.025581 -0.014970               55.0   \n",
       "2112477  0.001118        27.0  1.260330 -0.157878              242.0   \n",
       "2112478  0.001118        28.0 -0.157878 -0.226525              241.0   \n",
       "\n",
       "              MKT        ep  ep_recent  fenweishu_guimo  \n",
       "0       -0.125017  0.078427   0.078427     3.958033e+08  \n",
       "1       -0.022778  0.077763   0.077763     3.907805e+08  \n",
       "2        0.122163  0.076823   0.076823     4.341120e+08  \n",
       "3       -0.113023  0.085306   0.085306     3.835094e+08  \n",
       "4        0.166736  0.084349   0.084349     4.590161e+08  \n",
       "...           ...       ...        ...              ...  \n",
       "2112451 -0.020875       NaN        NaN     3.370444e+09  \n",
       "2112452 -0.065953       NaN        NaN     3.024944e+09  \n",
       "2112453 -0.042599       NaN        NaN     3.165959e+09  \n",
       "2112477 -0.004527       NaN        NaN     3.234660e+09  \n",
       "2112478  0.008606       NaN        NaN     3.392681e+09  \n",
       "\n",
       "[581929 rows x 27 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cross_new = pd.merge(cross,fenweishu,on='month',how='left')\n",
    "cross_new = cross_new[cross_new['totalvalue'] > cross_new['fenweishu_guimo']]\n",
    "cross_new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "46cc3941",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>Trdmnt</th>\n",
       "      <th>Opndt</th>\n",
       "      <th>Mopnprc</th>\n",
       "      <th>Clsdt</th>\n",
       "      <th>Mclsprc</th>\n",
       "      <th>Mnshrtrd</th>\n",
       "      <th>Mnvaltrd</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>Ndaytrd</th>\n",
       "      <th>Return</th>\n",
       "      <th>Mretnd</th>\n",
       "      <th>Markettype</th>\n",
       "      <th>Capchgdt</th>\n",
       "      <th>Ahshrtrd_M</th>\n",
       "      <th>Ahvaltrd_M</th>\n",
       "      <th>month</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>list_month</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>Cumsum_tradingday</th>\n",
       "      <th>MKT</th>\n",
       "      <th>ep</th>\n",
       "      <th>ep_recent</th>\n",
       "      <th>fenweishu_guimo</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-01</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.50</td>\n",
       "      <td>27.0</td>\n",
       "      <td>10.54</td>\n",
       "      <td>17488100.0</td>\n",
       "      <td>1.867690e+08</td>\n",
       "      <td>3.134297e+09</td>\n",
       "      <td>4.543463e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-01-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>46.0</td>\n",
       "      <td>-0.002994</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>247.0</td>\n",
       "      <td>-0.125017</td>\n",
       "      <td>0.078427</td>\n",
       "      <td>0.078427</td>\n",
       "      <td>3.958033e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-02</td>\n",
       "      <td>13.0</td>\n",
       "      <td>10.60</td>\n",
       "      <td>28.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>8544200.0</td>\n",
       "      <td>9.192790e+07</td>\n",
       "      <td>3.161060e+09</td>\n",
       "      <td>4.582260e+09</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-02-28</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>47.0</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>244.0</td>\n",
       "      <td>-0.022778</td>\n",
       "      <td>0.077763</td>\n",
       "      <td>0.077763</td>\n",
       "      <td>3.907805e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-03</td>\n",
       "      <td>1.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>31.0</td>\n",
       "      <td>10.76</td>\n",
       "      <td>18810600.0</td>\n",
       "      <td>2.059094e+08</td>\n",
       "      <td>3.199719e+09</td>\n",
       "      <td>4.638299e+09</td>\n",
       "      <td>23.0</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-03-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>244.0</td>\n",
       "      <td>0.122163</td>\n",
       "      <td>0.076823</td>\n",
       "      <td>0.076823</td>\n",
       "      <td>4.341120e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-04</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.78</td>\n",
       "      <td>28.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>13235500.0</td>\n",
       "      <td>1.380604e+08</td>\n",
       "      <td>2.881531e+09</td>\n",
       "      <td>4.177055e+09</td>\n",
       "      <td>20.0</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-04-30</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>49.0</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>243.0</td>\n",
       "      <td>-0.113023</td>\n",
       "      <td>0.085306</td>\n",
       "      <td>0.085306</td>\n",
       "      <td>3.835094e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-05</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>31.0</td>\n",
       "      <td>9.80</td>\n",
       "      <td>53197900.0</td>\n",
       "      <td>6.049730e+08</td>\n",
       "      <td>2.914242e+09</td>\n",
       "      <td>4.224473e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-05-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>-0.073005</td>\n",
       "      <td>244.0</td>\n",
       "      <td>0.166736</td>\n",
       "      <td>0.084349</td>\n",
       "      <td>0.084349</td>\n",
       "      <td>4.590161e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1779475</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-08</td>\n",
       "      <td>1.0</td>\n",
       "      <td>11.51</td>\n",
       "      <td>30.0</td>\n",
       "      <td>10.74</td>\n",
       "      <td>60492042.0</td>\n",
       "      <td>6.675452e+08</td>\n",
       "      <td>6.300920e+09</td>\n",
       "      <td>8.353334e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>-0.065274</td>\n",
       "      <td>-0.065274</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2022-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-08-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>36.0</td>\n",
       "      <td>-0.066392</td>\n",
       "      <td>0.105958</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.032586</td>\n",
       "      <td>0.079184</td>\n",
       "      <td>0.046498</td>\n",
       "      <td>2.442662e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1779476</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-09</td>\n",
       "      <td>2.0</td>\n",
       "      <td>10.56</td>\n",
       "      <td>30.0</td>\n",
       "      <td>11.89</td>\n",
       "      <td>68255221.0</td>\n",
       "      <td>7.093424e+08</td>\n",
       "      <td>9.247778e+09</td>\n",
       "      <td>9.247778e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.107076</td>\n",
       "      <td>0.107076</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2024-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-09-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>37.0</td>\n",
       "      <td>0.105958</td>\n",
       "      <td>-0.105407</td>\n",
       "      <td>241.0</td>\n",
       "      <td>0.194874</td>\n",
       "      <td>0.071525</td>\n",
       "      <td>0.042001</td>\n",
       "      <td>3.012217e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1779477</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-10</td>\n",
       "      <td>8.0</td>\n",
       "      <td>12.91</td>\n",
       "      <td>31.0</td>\n",
       "      <td>10.65</td>\n",
       "      <td>100720810.0</td>\n",
       "      <td>1.106652e+09</td>\n",
       "      <td>8.283334e+09</td>\n",
       "      <td>8.283334e+09</td>\n",
       "      <td>18.0</td>\n",
       "      <td>-0.104289</td>\n",
       "      <td>-0.104289</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2024-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-10-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>38.0</td>\n",
       "      <td>-0.105407</td>\n",
       "      <td>0.078694</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.004527</td>\n",
       "      <td>0.077932</td>\n",
       "      <td>0.063816</td>\n",
       "      <td>3.234660e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1779478</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-11</td>\n",
       "      <td>1.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>29.0</td>\n",
       "      <td>11.50</td>\n",
       "      <td>108258572.0</td>\n",
       "      <td>1.199394e+09</td>\n",
       "      <td>8.944445e+09</td>\n",
       "      <td>8.944445e+09</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.079812</td>\n",
       "      <td>0.079812</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2024-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-11-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0.078694</td>\n",
       "      <td>-0.014161</td>\n",
       "      <td>241.0</td>\n",
       "      <td>0.008606</td>\n",
       "      <td>0.072171</td>\n",
       "      <td>0.059100</td>\n",
       "      <td>3.392681e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1779479</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-12</td>\n",
       "      <td>2.0</td>\n",
       "      <td>11.48</td>\n",
       "      <td>31.0</td>\n",
       "      <td>11.35</td>\n",
       "      <td>124660340.0</td>\n",
       "      <td>1.443746e+09</td>\n",
       "      <td>8.827778e+09</td>\n",
       "      <td>8.827778e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>-0.013043</td>\n",
       "      <td>-0.013043</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2024-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-12-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>40.0</td>\n",
       "      <td>-0.014161</td>\n",
       "      <td>NaN</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.003797</td>\n",
       "      <td>0.073125</td>\n",
       "      <td>0.059881</td>\n",
       "      <td>3.176529e+09</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>499331 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          Stkcd   Trdmnt  Opndt  Mopnprc  Clsdt  Mclsprc     Mnshrtrd  \\\n",
       "0        000001  1995-01    3.0    10.50   27.0    10.54   17488100.0   \n",
       "1        000001  1995-02   13.0    10.60   28.0    10.63    8544200.0   \n",
       "2        000001  1995-03    1.0    10.63   31.0    10.76   18810600.0   \n",
       "3        000001  1995-04    3.0    10.78   28.0     9.69   13235500.0   \n",
       "4        000001  1995-05    2.0     9.69   31.0     9.80   53197900.0   \n",
       "...         ...      ...    ...      ...    ...      ...          ...   \n",
       "1779475  605599  2024-08    1.0    11.51   30.0    10.74   60492042.0   \n",
       "1779476  605599  2024-09    2.0    10.56   30.0    11.89   68255221.0   \n",
       "1779477  605599  2024-10    8.0    12.91   31.0    10.65  100720810.0   \n",
       "1779478  605599  2024-11    1.0    10.63   29.0    11.50  108258572.0   \n",
       "1779479  605599  2024-12    2.0    11.48   31.0    11.35  124660340.0   \n",
       "\n",
       "             Mnvaltrd  floatingvalue    totalvalue  Ndaytrd    Return  \\\n",
       "0        1.867690e+08   3.134297e+09  4.543463e+09     19.0  0.005725   \n",
       "1        9.192790e+07   3.161060e+09  4.582260e+09     12.0  0.008539   \n",
       "2        2.059094e+08   3.199719e+09  4.638299e+09     23.0  0.012230   \n",
       "3        1.380604e+08   2.881531e+09  4.177055e+09     20.0 -0.099442   \n",
       "4        6.049730e+08   2.914242e+09  4.224473e+09     22.0  0.011352   \n",
       "...               ...            ...           ...      ...       ...   \n",
       "1779475  6.675452e+08   6.300920e+09  8.353334e+09     22.0 -0.065274   \n",
       "1779476  7.093424e+08   9.247778e+09  9.247778e+09     19.0  0.107076   \n",
       "1779477  1.106652e+09   8.283334e+09  8.283334e+09     18.0 -0.104289   \n",
       "1779478  1.199394e+09   8.944445e+09  8.944445e+09     21.0  0.079812   \n",
       "1779479  1.443746e+09   8.827778e+09  8.827778e+09     22.0 -0.013043   \n",
       "\n",
       "           Mretnd  Markettype    Capchgdt  Ahshrtrd_M  Ahvaltrd_M      month  \\\n",
       "0        0.005725         4.0  1994-09-02         NaN         NaN 1995-01-31   \n",
       "1        0.008539         4.0  1994-09-02         NaN         NaN 1995-02-28   \n",
       "2        0.012230         4.0  1994-09-02         NaN         NaN 1995-03-31   \n",
       "3       -0.099442         4.0  1994-09-02         NaN         NaN 1995-04-30   \n",
       "4        0.011352         4.0  1994-09-02         NaN         NaN 1995-05-31   \n",
       "...           ...         ...         ...         ...         ...        ...   \n",
       "1779475 -0.065274         1.0  2022-09-09         0.0         0.0 2024-08-31   \n",
       "1779476  0.107076         1.0  2024-09-09         0.0         0.0 2024-09-30   \n",
       "1779477 -0.104289         1.0  2024-09-09         0.0         0.0 2024-10-31   \n",
       "1779478  0.079812         1.0  2024-09-09         0.0         0.0 2024-11-30   \n",
       "1779479 -0.013043         1.0  2024-09-09         0.0         0.0 2024-12-31   \n",
       "\n",
       "          rfmonth  list_month       ret  next_ret  Cumsum_tradingday  \\\n",
       "0        0.008719        46.0 -0.002994 -0.000180              247.0   \n",
       "1        0.008719        47.0 -0.000180  0.003511              244.0   \n",
       "2        0.008719        48.0  0.003511 -0.108161              244.0   \n",
       "3        0.008719        49.0 -0.108161  0.002633              243.0   \n",
       "4        0.008719        50.0  0.002633 -0.073005              244.0   \n",
       "...           ...         ...       ...       ...                ...   \n",
       "1779475  0.001118        36.0 -0.066392  0.105958              242.0   \n",
       "1779476  0.001118        37.0  0.105958 -0.105407              241.0   \n",
       "1779477  0.001118        38.0 -0.105407  0.078694              242.0   \n",
       "1779478  0.001118        39.0  0.078694 -0.014161              241.0   \n",
       "1779479  0.001118        40.0 -0.014161       NaN              242.0   \n",
       "\n",
       "              MKT        ep  ep_recent  fenweishu_guimo  \n",
       "0       -0.125017  0.078427   0.078427     3.958033e+08  \n",
       "1       -0.022778  0.077763   0.077763     3.907805e+08  \n",
       "2        0.122163  0.076823   0.076823     4.341120e+08  \n",
       "3       -0.113023  0.085306   0.085306     3.835094e+08  \n",
       "4        0.166736  0.084349   0.084349     4.590161e+08  \n",
       "...           ...       ...        ...              ...  \n",
       "1779475 -0.032586  0.079184   0.046498     2.442662e+09  \n",
       "1779476  0.194874  0.071525   0.042001     3.012217e+09  \n",
       "1779477 -0.004527  0.077932   0.063816     3.234660e+09  \n",
       "1779478  0.008606  0.072171   0.059100     3.392681e+09  \n",
       "1779479 -0.003797  0.073125   0.059881     3.176529e+09  \n",
       "\n",
       "[499331 rows x 27 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cross_new = cross_new[cross_new['Ndaytrd'] >= 12]\n",
    "# cross_new = cross_new[cross_new['Clsdt'] >= 5]\n",
    "cross_new = cross_new[cross_new['list_month'] > 6]\n",
    "cross_new = cross_new[cross_new['Cumsum_tradingday'] >= 120]\n",
    "cross_new = cross_new[(cross_new['Markettype'] == 1) | (cross_new['Markettype'] == 4) | (cross_new['Markettype'] == 16)] # 上海A 深圳A 创业板\n",
    "# ep是完整的\n",
    "cross_new = cross_new.dropna(subset=['ep'])\n",
    "cross_new"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "07ab2c52",
   "metadata": {},
   "source": [
    "规模、价值分组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "0303ec14",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>guimo</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1995-01-31</th>\n",
       "      <td>8.413909e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-02-28</th>\n",
       "      <td>8.085674e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-03-31</th>\n",
       "      <td>9.415474e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-04-30</th>\n",
       "      <td>8.264294e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-05-31</th>\n",
       "      <td>9.532519e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-08-31</th>\n",
       "      <td>5.863931e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-30</th>\n",
       "      <td>7.218455e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-10-31</th>\n",
       "      <td>7.787871e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-11-30</th>\n",
       "      <td>8.019636e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-12-31</th>\n",
       "      <td>7.700454e+09</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>357 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                   guimo\n",
       "month                   \n",
       "1995-01-31  8.413909e+08\n",
       "1995-02-28  8.085674e+08\n",
       "1995-03-31  9.415474e+08\n",
       "1995-04-30  8.264294e+08\n",
       "1995-05-31  9.532519e+08\n",
       "...                  ...\n",
       "2024-08-31  5.863931e+09\n",
       "2024-09-30  7.218455e+09\n",
       "2024-10-31  7.787871e+09\n",
       "2024-11-30  8.019636e+09\n",
       "2024-12-31  7.700454e+09\n",
       "\n",
       "[357 rows x 1 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "guimo = cross_new.groupby(['month'])['totalvalue'].quantile(0.5).to_frame()\n",
    "guimo.columns = ['guimo']\n",
    "guimo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "56733e27",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jiazhi_30</th>\n",
       "      <th>jiazhi_70</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1995-01-31</th>\n",
       "      <td>0.028942</td>\n",
       "      <td>0.079487</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-02-28</th>\n",
       "      <td>0.033836</td>\n",
       "      <td>0.075549</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-03-31</th>\n",
       "      <td>0.028213</td>\n",
       "      <td>0.062519</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-04-30</th>\n",
       "      <td>0.037206</td>\n",
       "      <td>0.086090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-05-31</th>\n",
       "      <td>0.030822</td>\n",
       "      <td>0.072632</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-08-31</th>\n",
       "      <td>0.008065</td>\n",
       "      <td>0.051295</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-30</th>\n",
       "      <td>0.005733</td>\n",
       "      <td>0.042326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-10-31</th>\n",
       "      <td>0.003594</td>\n",
       "      <td>0.040937</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-11-30</th>\n",
       "      <td>0.003567</td>\n",
       "      <td>0.039460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-12-31</th>\n",
       "      <td>0.004249</td>\n",
       "      <td>0.040510</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>357 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            jiazhi_30  jiazhi_70\n",
       "month                           \n",
       "1995-01-31   0.028942   0.079487\n",
       "1995-02-28   0.033836   0.075549\n",
       "1995-03-31   0.028213   0.062519\n",
       "1995-04-30   0.037206   0.086090\n",
       "1995-05-31   0.030822   0.072632\n",
       "...               ...        ...\n",
       "2024-08-31   0.008065   0.051295\n",
       "2024-09-30   0.005733   0.042326\n",
       "2024-10-31   0.003594   0.040937\n",
       "2024-11-30   0.003567   0.039460\n",
       "2024-12-31   0.004249   0.040510\n",
       "\n",
       "[357 rows x 2 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "jiazhi = cross_new.groupby(['month'])['ep'].quantile([0.3,0.7]).to_frame()\n",
    "jiazhi.reset_index(inplace=True)\n",
    "jiazhi = jiazhi.pivot_table(index='month',columns='level_1',values='ep')\n",
    "jiazhi.columns = ['jiazhi_30','jiazhi_70']\n",
    "jiazhi"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79ca91dd",
   "metadata": {},
   "source": [
    "合并数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "5a2f6ad1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>Trdmnt</th>\n",
       "      <th>Opndt</th>\n",
       "      <th>Mopnprc</th>\n",
       "      <th>Clsdt</th>\n",
       "      <th>Mclsprc</th>\n",
       "      <th>Mnshrtrd</th>\n",
       "      <th>Mnvaltrd</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>Ndaytrd</th>\n",
       "      <th>Return</th>\n",
       "      <th>Mretnd</th>\n",
       "      <th>Markettype</th>\n",
       "      <th>Capchgdt</th>\n",
       "      <th>Ahshrtrd_M</th>\n",
       "      <th>Ahvaltrd_M</th>\n",
       "      <th>month</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>list_month</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>Cumsum_tradingday</th>\n",
       "      <th>MKT</th>\n",
       "      <th>ep</th>\n",
       "      <th>ep_recent</th>\n",
       "      <th>fenweishu_guimo</th>\n",
       "      <th>guimo</th>\n",
       "      <th>jiazhi_30</th>\n",
       "      <th>jiazhi_70</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-01</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.50</td>\n",
       "      <td>27.0</td>\n",
       "      <td>10.54</td>\n",
       "      <td>17488100.0</td>\n",
       "      <td>1.867690e+08</td>\n",
       "      <td>3.134297e+09</td>\n",
       "      <td>4.543463e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-01-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>46.0</td>\n",
       "      <td>-0.002994</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>247.0</td>\n",
       "      <td>-0.125017</td>\n",
       "      <td>0.078427</td>\n",
       "      <td>0.078427</td>\n",
       "      <td>3.958033e+08</td>\n",
       "      <td>8.413909e+08</td>\n",
       "      <td>0.028942</td>\n",
       "      <td>0.079487</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-02</td>\n",
       "      <td>13.0</td>\n",
       "      <td>10.60</td>\n",
       "      <td>28.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>8544200.0</td>\n",
       "      <td>9.192790e+07</td>\n",
       "      <td>3.161060e+09</td>\n",
       "      <td>4.582260e+09</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-02-28</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>47.0</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>244.0</td>\n",
       "      <td>-0.022778</td>\n",
       "      <td>0.077763</td>\n",
       "      <td>0.077763</td>\n",
       "      <td>3.907805e+08</td>\n",
       "      <td>8.085674e+08</td>\n",
       "      <td>0.033836</td>\n",
       "      <td>0.075549</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-03</td>\n",
       "      <td>1.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>31.0</td>\n",
       "      <td>10.76</td>\n",
       "      <td>18810600.0</td>\n",
       "      <td>2.059094e+08</td>\n",
       "      <td>3.199719e+09</td>\n",
       "      <td>4.638299e+09</td>\n",
       "      <td>23.0</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-03-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>244.0</td>\n",
       "      <td>0.122163</td>\n",
       "      <td>0.076823</td>\n",
       "      <td>0.076823</td>\n",
       "      <td>4.341120e+08</td>\n",
       "      <td>9.415474e+08</td>\n",
       "      <td>0.028213</td>\n",
       "      <td>0.062519</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-04</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.78</td>\n",
       "      <td>28.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>13235500.0</td>\n",
       "      <td>1.380604e+08</td>\n",
       "      <td>2.881531e+09</td>\n",
       "      <td>4.177055e+09</td>\n",
       "      <td>20.0</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-04-30</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>49.0</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>243.0</td>\n",
       "      <td>-0.113023</td>\n",
       "      <td>0.085306</td>\n",
       "      <td>0.085306</td>\n",
       "      <td>3.835094e+08</td>\n",
       "      <td>8.264294e+08</td>\n",
       "      <td>0.037206</td>\n",
       "      <td>0.086090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-05</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>31.0</td>\n",
       "      <td>9.80</td>\n",
       "      <td>53197900.0</td>\n",
       "      <td>6.049730e+08</td>\n",
       "      <td>2.914242e+09</td>\n",
       "      <td>4.224473e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-05-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>-0.073005</td>\n",
       "      <td>244.0</td>\n",
       "      <td>0.166736</td>\n",
       "      <td>0.084349</td>\n",
       "      <td>0.084349</td>\n",
       "      <td>4.590161e+08</td>\n",
       "      <td>9.532519e+08</td>\n",
       "      <td>0.030822</td>\n",
       "      <td>0.072632</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499326</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-08</td>\n",
       "      <td>1.0</td>\n",
       "      <td>11.51</td>\n",
       "      <td>30.0</td>\n",
       "      <td>10.74</td>\n",
       "      <td>60492042.0</td>\n",
       "      <td>6.675452e+08</td>\n",
       "      <td>6.300920e+09</td>\n",
       "      <td>8.353334e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>-0.065274</td>\n",
       "      <td>-0.065274</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2022-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-08-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>36.0</td>\n",
       "      <td>-0.066392</td>\n",
       "      <td>0.105958</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.032586</td>\n",
       "      <td>0.079184</td>\n",
       "      <td>0.046498</td>\n",
       "      <td>2.442662e+09</td>\n",
       "      <td>5.863931e+09</td>\n",
       "      <td>0.008065</td>\n",
       "      <td>0.051295</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499327</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-09</td>\n",
       "      <td>2.0</td>\n",
       "      <td>10.56</td>\n",
       "      <td>30.0</td>\n",
       "      <td>11.89</td>\n",
       "      <td>68255221.0</td>\n",
       "      <td>7.093424e+08</td>\n",
       "      <td>9.247778e+09</td>\n",
       "      <td>9.247778e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.107076</td>\n",
       "      <td>0.107076</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2024-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-09-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>37.0</td>\n",
       "      <td>0.105958</td>\n",
       "      <td>-0.105407</td>\n",
       "      <td>241.0</td>\n",
       "      <td>0.194874</td>\n",
       "      <td>0.071525</td>\n",
       "      <td>0.042001</td>\n",
       "      <td>3.012217e+09</td>\n",
       "      <td>7.218455e+09</td>\n",
       "      <td>0.005733</td>\n",
       "      <td>0.042326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499328</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-10</td>\n",
       "      <td>8.0</td>\n",
       "      <td>12.91</td>\n",
       "      <td>31.0</td>\n",
       "      <td>10.65</td>\n",
       "      <td>100720810.0</td>\n",
       "      <td>1.106652e+09</td>\n",
       "      <td>8.283334e+09</td>\n",
       "      <td>8.283334e+09</td>\n",
       "      <td>18.0</td>\n",
       "      <td>-0.104289</td>\n",
       "      <td>-0.104289</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2024-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-10-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>38.0</td>\n",
       "      <td>-0.105407</td>\n",
       "      <td>0.078694</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.004527</td>\n",
       "      <td>0.077932</td>\n",
       "      <td>0.063816</td>\n",
       "      <td>3.234660e+09</td>\n",
       "      <td>7.787871e+09</td>\n",
       "      <td>0.003594</td>\n",
       "      <td>0.040937</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499329</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-11</td>\n",
       "      <td>1.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>29.0</td>\n",
       "      <td>11.50</td>\n",
       "      <td>108258572.0</td>\n",
       "      <td>1.199394e+09</td>\n",
       "      <td>8.944445e+09</td>\n",
       "      <td>8.944445e+09</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.079812</td>\n",
       "      <td>0.079812</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2024-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-11-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0.078694</td>\n",
       "      <td>-0.014161</td>\n",
       "      <td>241.0</td>\n",
       "      <td>0.008606</td>\n",
       "      <td>0.072171</td>\n",
       "      <td>0.059100</td>\n",
       "      <td>3.392681e+09</td>\n",
       "      <td>8.019636e+09</td>\n",
       "      <td>0.003567</td>\n",
       "      <td>0.039460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499330</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-12</td>\n",
       "      <td>2.0</td>\n",
       "      <td>11.48</td>\n",
       "      <td>31.0</td>\n",
       "      <td>11.35</td>\n",
       "      <td>124660340.0</td>\n",
       "      <td>1.443746e+09</td>\n",
       "      <td>8.827778e+09</td>\n",
       "      <td>8.827778e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>-0.013043</td>\n",
       "      <td>-0.013043</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2024-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-12-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>40.0</td>\n",
       "      <td>-0.014161</td>\n",
       "      <td>NaN</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.003797</td>\n",
       "      <td>0.073125</td>\n",
       "      <td>0.059881</td>\n",
       "      <td>3.176529e+09</td>\n",
       "      <td>7.700454e+09</td>\n",
       "      <td>0.004249</td>\n",
       "      <td>0.040510</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>499331 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Stkcd   Trdmnt  Opndt  Mopnprc  Clsdt  Mclsprc     Mnshrtrd  \\\n",
       "0       000001  1995-01    3.0    10.50   27.0    10.54   17488100.0   \n",
       "1       000001  1995-02   13.0    10.60   28.0    10.63    8544200.0   \n",
       "2       000001  1995-03    1.0    10.63   31.0    10.76   18810600.0   \n",
       "3       000001  1995-04    3.0    10.78   28.0     9.69   13235500.0   \n",
       "4       000001  1995-05    2.0     9.69   31.0     9.80   53197900.0   \n",
       "...        ...      ...    ...      ...    ...      ...          ...   \n",
       "499326  605599  2024-08    1.0    11.51   30.0    10.74   60492042.0   \n",
       "499327  605599  2024-09    2.0    10.56   30.0    11.89   68255221.0   \n",
       "499328  605599  2024-10    8.0    12.91   31.0    10.65  100720810.0   \n",
       "499329  605599  2024-11    1.0    10.63   29.0    11.50  108258572.0   \n",
       "499330  605599  2024-12    2.0    11.48   31.0    11.35  124660340.0   \n",
       "\n",
       "            Mnvaltrd  floatingvalue    totalvalue  Ndaytrd    Return  \\\n",
       "0       1.867690e+08   3.134297e+09  4.543463e+09     19.0  0.005725   \n",
       "1       9.192790e+07   3.161060e+09  4.582260e+09     12.0  0.008539   \n",
       "2       2.059094e+08   3.199719e+09  4.638299e+09     23.0  0.012230   \n",
       "3       1.380604e+08   2.881531e+09  4.177055e+09     20.0 -0.099442   \n",
       "4       6.049730e+08   2.914242e+09  4.224473e+09     22.0  0.011352   \n",
       "...              ...            ...           ...      ...       ...   \n",
       "499326  6.675452e+08   6.300920e+09  8.353334e+09     22.0 -0.065274   \n",
       "499327  7.093424e+08   9.247778e+09  9.247778e+09     19.0  0.107076   \n",
       "499328  1.106652e+09   8.283334e+09  8.283334e+09     18.0 -0.104289   \n",
       "499329  1.199394e+09   8.944445e+09  8.944445e+09     21.0  0.079812   \n",
       "499330  1.443746e+09   8.827778e+09  8.827778e+09     22.0 -0.013043   \n",
       "\n",
       "          Mretnd  Markettype    Capchgdt  Ahshrtrd_M  Ahvaltrd_M      month  \\\n",
       "0       0.005725         4.0  1994-09-02         NaN         NaN 1995-01-31   \n",
       "1       0.008539         4.0  1994-09-02         NaN         NaN 1995-02-28   \n",
       "2       0.012230         4.0  1994-09-02         NaN         NaN 1995-03-31   \n",
       "3      -0.099442         4.0  1994-09-02         NaN         NaN 1995-04-30   \n",
       "4       0.011352         4.0  1994-09-02         NaN         NaN 1995-05-31   \n",
       "...          ...         ...         ...         ...         ...        ...   \n",
       "499326 -0.065274         1.0  2022-09-09         0.0         0.0 2024-08-31   \n",
       "499327  0.107076         1.0  2024-09-09         0.0         0.0 2024-09-30   \n",
       "499328 -0.104289         1.0  2024-09-09         0.0         0.0 2024-10-31   \n",
       "499329  0.079812         1.0  2024-09-09         0.0         0.0 2024-11-30   \n",
       "499330 -0.013043         1.0  2024-09-09         0.0         0.0 2024-12-31   \n",
       "\n",
       "         rfmonth  list_month       ret  next_ret  Cumsum_tradingday       MKT  \\\n",
       "0       0.008719        46.0 -0.002994 -0.000180              247.0 -0.125017   \n",
       "1       0.008719        47.0 -0.000180  0.003511              244.0 -0.022778   \n",
       "2       0.008719        48.0  0.003511 -0.108161              244.0  0.122163   \n",
       "3       0.008719        49.0 -0.108161  0.002633              243.0 -0.113023   \n",
       "4       0.008719        50.0  0.002633 -0.073005              244.0  0.166736   \n",
       "...          ...         ...       ...       ...                ...       ...   \n",
       "499326  0.001118        36.0 -0.066392  0.105958              242.0 -0.032586   \n",
       "499327  0.001118        37.0  0.105958 -0.105407              241.0  0.194874   \n",
       "499328  0.001118        38.0 -0.105407  0.078694              242.0 -0.004527   \n",
       "499329  0.001118        39.0  0.078694 -0.014161              241.0  0.008606   \n",
       "499330  0.001118        40.0 -0.014161       NaN              242.0 -0.003797   \n",
       "\n",
       "              ep  ep_recent  fenweishu_guimo         guimo  jiazhi_30  \\\n",
       "0       0.078427   0.078427     3.958033e+08  8.413909e+08   0.028942   \n",
       "1       0.077763   0.077763     3.907805e+08  8.085674e+08   0.033836   \n",
       "2       0.076823   0.076823     4.341120e+08  9.415474e+08   0.028213   \n",
       "3       0.085306   0.085306     3.835094e+08  8.264294e+08   0.037206   \n",
       "4       0.084349   0.084349     4.590161e+08  9.532519e+08   0.030822   \n",
       "...          ...        ...              ...           ...        ...   \n",
       "499326  0.079184   0.046498     2.442662e+09  5.863931e+09   0.008065   \n",
       "499327  0.071525   0.042001     3.012217e+09  7.218455e+09   0.005733   \n",
       "499328  0.077932   0.063816     3.234660e+09  7.787871e+09   0.003594   \n",
       "499329  0.072171   0.059100     3.392681e+09  8.019636e+09   0.003567   \n",
       "499330  0.073125   0.059881     3.176529e+09  7.700454e+09   0.004249   \n",
       "\n",
       "        jiazhi_70  \n",
       "0        0.079487  \n",
       "1        0.075549  \n",
       "2        0.062519  \n",
       "3        0.086090  \n",
       "4        0.072632  \n",
       "...           ...  \n",
       "499326   0.051295  \n",
       "499327   0.042326  \n",
       "499328   0.040937  \n",
       "499329   0.039460  \n",
       "499330   0.040510  \n",
       "\n",
       "[499331 rows x 30 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cross_new = pd.merge(cross_new,guimo,on='month',how='left')\n",
    "cross_new = pd.merge(cross_new,jiazhi,on='month',how='left')\n",
    "cross_new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "2661f69a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>Trdmnt</th>\n",
       "      <th>Opndt</th>\n",
       "      <th>Mopnprc</th>\n",
       "      <th>Clsdt</th>\n",
       "      <th>Mclsprc</th>\n",
       "      <th>Mnshrtrd</th>\n",
       "      <th>Mnvaltrd</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>Ndaytrd</th>\n",
       "      <th>Return</th>\n",
       "      <th>Mretnd</th>\n",
       "      <th>Markettype</th>\n",
       "      <th>Capchgdt</th>\n",
       "      <th>Ahshrtrd_M</th>\n",
       "      <th>Ahvaltrd_M</th>\n",
       "      <th>month</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>list_month</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>Cumsum_tradingday</th>\n",
       "      <th>MKT</th>\n",
       "      <th>ep</th>\n",
       "      <th>ep_recent</th>\n",
       "      <th>fenweishu_guimo</th>\n",
       "      <th>guimo</th>\n",
       "      <th>jiazhi_30</th>\n",
       "      <th>jiazhi_70</th>\n",
       "      <th>size</th>\n",
       "      <th>value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-01</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.50</td>\n",
       "      <td>27.0</td>\n",
       "      <td>10.54</td>\n",
       "      <td>17488100.0</td>\n",
       "      <td>1.867690e+08</td>\n",
       "      <td>3.134297e+09</td>\n",
       "      <td>4.543463e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>0.005725</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-01-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>46.0</td>\n",
       "      <td>-0.002994</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>247.0</td>\n",
       "      <td>-0.125017</td>\n",
       "      <td>0.078427</td>\n",
       "      <td>0.078427</td>\n",
       "      <td>3.958033e+08</td>\n",
       "      <td>8.413909e+08</td>\n",
       "      <td>0.028942</td>\n",
       "      <td>0.079487</td>\n",
       "      <td>B</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-02</td>\n",
       "      <td>13.0</td>\n",
       "      <td>10.60</td>\n",
       "      <td>28.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>8544200.0</td>\n",
       "      <td>9.192790e+07</td>\n",
       "      <td>3.161060e+09</td>\n",
       "      <td>4.582260e+09</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>0.008539</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-02-28</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>47.0</td>\n",
       "      <td>-0.000180</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>244.0</td>\n",
       "      <td>-0.022778</td>\n",
       "      <td>0.077763</td>\n",
       "      <td>0.077763</td>\n",
       "      <td>3.907805e+08</td>\n",
       "      <td>8.085674e+08</td>\n",
       "      <td>0.033836</td>\n",
       "      <td>0.075549</td>\n",
       "      <td>B</td>\n",
       "      <td>V</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-03</td>\n",
       "      <td>1.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>31.0</td>\n",
       "      <td>10.76</td>\n",
       "      <td>18810600.0</td>\n",
       "      <td>2.059094e+08</td>\n",
       "      <td>3.199719e+09</td>\n",
       "      <td>4.638299e+09</td>\n",
       "      <td>23.0</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>0.012230</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-03-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0.003511</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>244.0</td>\n",
       "      <td>0.122163</td>\n",
       "      <td>0.076823</td>\n",
       "      <td>0.076823</td>\n",
       "      <td>4.341120e+08</td>\n",
       "      <td>9.415474e+08</td>\n",
       "      <td>0.028213</td>\n",
       "      <td>0.062519</td>\n",
       "      <td>B</td>\n",
       "      <td>V</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-04</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.78</td>\n",
       "      <td>28.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>13235500.0</td>\n",
       "      <td>1.380604e+08</td>\n",
       "      <td>2.881531e+09</td>\n",
       "      <td>4.177055e+09</td>\n",
       "      <td>20.0</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>-0.099442</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-04-30</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>49.0</td>\n",
       "      <td>-0.108161</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>243.0</td>\n",
       "      <td>-0.113023</td>\n",
       "      <td>0.085306</td>\n",
       "      <td>0.085306</td>\n",
       "      <td>3.835094e+08</td>\n",
       "      <td>8.264294e+08</td>\n",
       "      <td>0.037206</td>\n",
       "      <td>0.086090</td>\n",
       "      <td>B</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1995-05</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.69</td>\n",
       "      <td>31.0</td>\n",
       "      <td>9.80</td>\n",
       "      <td>53197900.0</td>\n",
       "      <td>6.049730e+08</td>\n",
       "      <td>2.914242e+09</td>\n",
       "      <td>4.224473e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>0.011352</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1994-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1995-05-31</td>\n",
       "      <td>0.008719</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.002633</td>\n",
       "      <td>-0.073005</td>\n",
       "      <td>244.0</td>\n",
       "      <td>0.166736</td>\n",
       "      <td>0.084349</td>\n",
       "      <td>0.084349</td>\n",
       "      <td>4.590161e+08</td>\n",
       "      <td>9.532519e+08</td>\n",
       "      <td>0.030822</td>\n",
       "      <td>0.072632</td>\n",
       "      <td>B</td>\n",
       "      <td>V</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499325</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-07</td>\n",
       "      <td>1.0</td>\n",
       "      <td>12.78</td>\n",
       "      <td>31.0</td>\n",
       "      <td>11.49</td>\n",
       "      <td>54949980.0</td>\n",
       "      <td>6.610917e+08</td>\n",
       "      <td>6.740928e+09</td>\n",
       "      <td>8.936667e+09</td>\n",
       "      <td>23.0</td>\n",
       "      <td>-0.097408</td>\n",
       "      <td>-0.097408</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2022-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-07-31</td>\n",
       "      <td>0.001184</td>\n",
       "      <td>35.0</td>\n",
       "      <td>-0.098592</td>\n",
       "      <td>-0.066392</td>\n",
       "      <td>243.0</td>\n",
       "      <td>-0.000624</td>\n",
       "      <td>0.078272</td>\n",
       "      <td>0.028314</td>\n",
       "      <td>2.521012e+09</td>\n",
       "      <td>6.148011e+09</td>\n",
       "      <td>0.008836</td>\n",
       "      <td>0.050913</td>\n",
       "      <td>B</td>\n",
       "      <td>V</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499326</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-08</td>\n",
       "      <td>1.0</td>\n",
       "      <td>11.51</td>\n",
       "      <td>30.0</td>\n",
       "      <td>10.74</td>\n",
       "      <td>60492042.0</td>\n",
       "      <td>6.675452e+08</td>\n",
       "      <td>6.300920e+09</td>\n",
       "      <td>8.353334e+09</td>\n",
       "      <td>22.0</td>\n",
       "      <td>-0.065274</td>\n",
       "      <td>-0.065274</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2022-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-08-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>36.0</td>\n",
       "      <td>-0.066392</td>\n",
       "      <td>0.105958</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.032586</td>\n",
       "      <td>0.079184</td>\n",
       "      <td>0.046498</td>\n",
       "      <td>2.442662e+09</td>\n",
       "      <td>5.863931e+09</td>\n",
       "      <td>0.008065</td>\n",
       "      <td>0.051295</td>\n",
       "      <td>B</td>\n",
       "      <td>V</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499327</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-09</td>\n",
       "      <td>2.0</td>\n",
       "      <td>10.56</td>\n",
       "      <td>30.0</td>\n",
       "      <td>11.89</td>\n",
       "      <td>68255221.0</td>\n",
       "      <td>7.093424e+08</td>\n",
       "      <td>9.247778e+09</td>\n",
       "      <td>9.247778e+09</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.107076</td>\n",
       "      <td>0.107076</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2024-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-09-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>37.0</td>\n",
       "      <td>0.105958</td>\n",
       "      <td>-0.105407</td>\n",
       "      <td>241.0</td>\n",
       "      <td>0.194874</td>\n",
       "      <td>0.071525</td>\n",
       "      <td>0.042001</td>\n",
       "      <td>3.012217e+09</td>\n",
       "      <td>7.218455e+09</td>\n",
       "      <td>0.005733</td>\n",
       "      <td>0.042326</td>\n",
       "      <td>B</td>\n",
       "      <td>V</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499328</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-10</td>\n",
       "      <td>8.0</td>\n",
       "      <td>12.91</td>\n",
       "      <td>31.0</td>\n",
       "      <td>10.65</td>\n",
       "      <td>100720810.0</td>\n",
       "      <td>1.106652e+09</td>\n",
       "      <td>8.283334e+09</td>\n",
       "      <td>8.283334e+09</td>\n",
       "      <td>18.0</td>\n",
       "      <td>-0.104289</td>\n",
       "      <td>-0.104289</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2024-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-10-31</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>38.0</td>\n",
       "      <td>-0.105407</td>\n",
       "      <td>0.078694</td>\n",
       "      <td>242.0</td>\n",
       "      <td>-0.004527</td>\n",
       "      <td>0.077932</td>\n",
       "      <td>0.063816</td>\n",
       "      <td>3.234660e+09</td>\n",
       "      <td>7.787871e+09</td>\n",
       "      <td>0.003594</td>\n",
       "      <td>0.040937</td>\n",
       "      <td>B</td>\n",
       "      <td>V</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499329</th>\n",
       "      <td>605599</td>\n",
       "      <td>2024-11</td>\n",
       "      <td>1.0</td>\n",
       "      <td>10.63</td>\n",
       "      <td>29.0</td>\n",
       "      <td>11.50</td>\n",
       "      <td>108258572.0</td>\n",
       "      <td>1.199394e+09</td>\n",
       "      <td>8.944445e+09</td>\n",
       "      <td>8.944445e+09</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.079812</td>\n",
       "      <td>0.079812</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2024-09-09</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2024-11-30</td>\n",
       "      <td>0.001118</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0.078694</td>\n",
       "      <td>-0.014161</td>\n",
       "      <td>241.0</td>\n",
       "      <td>0.008606</td>\n",
       "      <td>0.072171</td>\n",
       "      <td>0.059100</td>\n",
       "      <td>3.392681e+09</td>\n",
       "      <td>8.019636e+09</td>\n",
       "      <td>0.003567</td>\n",
       "      <td>0.039460</td>\n",
       "      <td>B</td>\n",
       "      <td>V</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>494815 rows × 32 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Stkcd   Trdmnt  Opndt  Mopnprc  Clsdt  Mclsprc     Mnshrtrd  \\\n",
       "0       000001  1995-01    3.0    10.50   27.0    10.54   17488100.0   \n",
       "1       000001  1995-02   13.0    10.60   28.0    10.63    8544200.0   \n",
       "2       000001  1995-03    1.0    10.63   31.0    10.76   18810600.0   \n",
       "3       000001  1995-04    3.0    10.78   28.0     9.69   13235500.0   \n",
       "4       000001  1995-05    2.0     9.69   31.0     9.80   53197900.0   \n",
       "...        ...      ...    ...      ...    ...      ...          ...   \n",
       "499325  605599  2024-07    1.0    12.78   31.0    11.49   54949980.0   \n",
       "499326  605599  2024-08    1.0    11.51   30.0    10.74   60492042.0   \n",
       "499327  605599  2024-09    2.0    10.56   30.0    11.89   68255221.0   \n",
       "499328  605599  2024-10    8.0    12.91   31.0    10.65  100720810.0   \n",
       "499329  605599  2024-11    1.0    10.63   29.0    11.50  108258572.0   \n",
       "\n",
       "            Mnvaltrd  floatingvalue    totalvalue  Ndaytrd    Return  \\\n",
       "0       1.867690e+08   3.134297e+09  4.543463e+09     19.0  0.005725   \n",
       "1       9.192790e+07   3.161060e+09  4.582260e+09     12.0  0.008539   \n",
       "2       2.059094e+08   3.199719e+09  4.638299e+09     23.0  0.012230   \n",
       "3       1.380604e+08   2.881531e+09  4.177055e+09     20.0 -0.099442   \n",
       "4       6.049730e+08   2.914242e+09  4.224473e+09     22.0  0.011352   \n",
       "...              ...            ...           ...      ...       ...   \n",
       "499325  6.610917e+08   6.740928e+09  8.936667e+09     23.0 -0.097408   \n",
       "499326  6.675452e+08   6.300920e+09  8.353334e+09     22.0 -0.065274   \n",
       "499327  7.093424e+08   9.247778e+09  9.247778e+09     19.0  0.107076   \n",
       "499328  1.106652e+09   8.283334e+09  8.283334e+09     18.0 -0.104289   \n",
       "499329  1.199394e+09   8.944445e+09  8.944445e+09     21.0  0.079812   \n",
       "\n",
       "          Mretnd  Markettype    Capchgdt  Ahshrtrd_M  Ahvaltrd_M      month  \\\n",
       "0       0.005725         4.0  1994-09-02         NaN         NaN 1995-01-31   \n",
       "1       0.008539         4.0  1994-09-02         NaN         NaN 1995-02-28   \n",
       "2       0.012230         4.0  1994-09-02         NaN         NaN 1995-03-31   \n",
       "3      -0.099442         4.0  1994-09-02         NaN         NaN 1995-04-30   \n",
       "4       0.011352         4.0  1994-09-02         NaN         NaN 1995-05-31   \n",
       "...          ...         ...         ...         ...         ...        ...   \n",
       "499325 -0.097408         1.0  2022-09-09         0.0         0.0 2024-07-31   \n",
       "499326 -0.065274         1.0  2022-09-09         0.0         0.0 2024-08-31   \n",
       "499327  0.107076         1.0  2024-09-09         0.0         0.0 2024-09-30   \n",
       "499328 -0.104289         1.0  2024-09-09         0.0         0.0 2024-10-31   \n",
       "499329  0.079812         1.0  2024-09-09         0.0         0.0 2024-11-30   \n",
       "\n",
       "         rfmonth  list_month       ret  next_ret  Cumsum_tradingday       MKT  \\\n",
       "0       0.008719        46.0 -0.002994 -0.000180              247.0 -0.125017   \n",
       "1       0.008719        47.0 -0.000180  0.003511              244.0 -0.022778   \n",
       "2       0.008719        48.0  0.003511 -0.108161              244.0  0.122163   \n",
       "3       0.008719        49.0 -0.108161  0.002633              243.0 -0.113023   \n",
       "4       0.008719        50.0  0.002633 -0.073005              244.0  0.166736   \n",
       "...          ...         ...       ...       ...                ...       ...   \n",
       "499325  0.001184        35.0 -0.098592 -0.066392              243.0 -0.000624   \n",
       "499326  0.001118        36.0 -0.066392  0.105958              242.0 -0.032586   \n",
       "499327  0.001118        37.0  0.105958 -0.105407              241.0  0.194874   \n",
       "499328  0.001118        38.0 -0.105407  0.078694              242.0 -0.004527   \n",
       "499329  0.001118        39.0  0.078694 -0.014161              241.0  0.008606   \n",
       "\n",
       "              ep  ep_recent  fenweishu_guimo         guimo  jiazhi_30  \\\n",
       "0       0.078427   0.078427     3.958033e+08  8.413909e+08   0.028942   \n",
       "1       0.077763   0.077763     3.907805e+08  8.085674e+08   0.033836   \n",
       "2       0.076823   0.076823     4.341120e+08  9.415474e+08   0.028213   \n",
       "3       0.085306   0.085306     3.835094e+08  8.264294e+08   0.037206   \n",
       "4       0.084349   0.084349     4.590161e+08  9.532519e+08   0.030822   \n",
       "...          ...        ...              ...           ...        ...   \n",
       "499325  0.078272   0.028314     2.521012e+09  6.148011e+09   0.008836   \n",
       "499326  0.079184   0.046498     2.442662e+09  5.863931e+09   0.008065   \n",
       "499327  0.071525   0.042001     3.012217e+09  7.218455e+09   0.005733   \n",
       "499328  0.077932   0.063816     3.234660e+09  7.787871e+09   0.003594   \n",
       "499329  0.072171   0.059100     3.392681e+09  8.019636e+09   0.003567   \n",
       "\n",
       "        jiazhi_70 size value  \n",
       "0        0.079487    B     M  \n",
       "1        0.075549    B     V  \n",
       "2        0.062519    B     V  \n",
       "3        0.086090    B     M  \n",
       "4        0.072632    B     V  \n",
       "...           ...  ...   ...  \n",
       "499325   0.050913    B     V  \n",
       "499326   0.051295    B     V  \n",
       "499327   0.042326    B     V  \n",
       "499328   0.040937    B     V  \n",
       "499329   0.039460    B     V  \n",
       "\n",
       "[494815 rows x 32 columns]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# note the totalvale > guimo will be big, else small\n",
    "# note the ep > jiazhi_70 will be value, else > jiazhi_30 will be median, else growth\n",
    "cross_new['size'] = np.where(cross_new['totalvalue'] > cross_new['guimo'],'B','S')\n",
    "cross_new['value'] = np.where(cross_new['ep'] > cross_new['jiazhi_70'],'V',\n",
    "                              np.where(cross_new['ep'] > cross_new['jiazhi_30'],'M','G'))\n",
    "cross_new = cross_new.dropna(subset=['next_ret','totalvalue'])\n",
    "cross_new"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf09c22c",
   "metadata": {},
   "source": [
    "计算交叉分组里的加权收益率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "4faa0dd7",
   "metadata": {},
   "outputs": [],
   "source": [
    "SV = cross_new[(cross_new['size'] == 'S') & (cross_new['value'] == 'V')].groupby(['month']).apply(lambda x: np.average(x['next_ret'],weights=x['totalvalue'])).to_frame()\n",
    "SV.columns = ['SV']\n",
    "SM = cross_new[(cross_new['size'] == 'S') & (cross_new['value'] == 'M')].groupby(['month']).apply(lambda x: np.average(x['next_ret'],weights=x['totalvalue'])).to_frame()\n",
    "SM.columns = ['SM']\n",
    "SG = cross_new[(cross_new['size'] == 'S') & (cross_new['value'] == 'G')].groupby(['month']).apply(lambda x: np.average(x['next_ret'],weights=x['totalvalue'])).to_frame()\n",
    "SG.columns = ['SG']\n",
    "BV = cross_new[(cross_new['size'] == 'B') & (cross_new['value'] == 'V')].groupby(['month']).apply(lambda x: np.average(x['next_ret'],weights=x['totalvalue'])).to_frame()\n",
    "BV.columns = ['BV']\n",
    "BM = cross_new[(cross_new['size'] == 'B') & (cross_new['value'] == 'M')].groupby(['month']).apply(lambda x: np.average(x['next_ret'],weights=x['totalvalue'])).to_frame()\n",
    "BM.columns = ['BM']\n",
    "BG = cross_new[(cross_new['size'] == 'B') & (cross_new['value'] == 'G')].groupby(['month']).apply(lambda x: np.average(x['next_ret'],weights=x['totalvalue'])).to_frame()\n",
    "BG.columns = ['BG']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "53356c84",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SV</th>\n",
       "      <th>SM</th>\n",
       "      <th>SG</th>\n",
       "      <th>BV</th>\n",
       "      <th>BM</th>\n",
       "      <th>BG</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2000-01-31</th>\n",
       "      <td>0.111051</td>\n",
       "      <td>0.135348</td>\n",
       "      <td>0.167612</td>\n",
       "      <td>0.104549</td>\n",
       "      <td>0.184193</td>\n",
       "      <td>0.168754</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-02-29</th>\n",
       "      <td>0.124971</td>\n",
       "      <td>0.139342</td>\n",
       "      <td>0.146752</td>\n",
       "      <td>0.062845</td>\n",
       "      <td>0.109953</td>\n",
       "      <td>0.159660</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-03-31</th>\n",
       "      <td>0.111485</td>\n",
       "      <td>0.089074</td>\n",
       "      <td>0.123222</td>\n",
       "      <td>0.038707</td>\n",
       "      <td>0.017311</td>\n",
       "      <td>0.019475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-04-30</th>\n",
       "      <td>0.020844</td>\n",
       "      <td>0.019261</td>\n",
       "      <td>0.015617</td>\n",
       "      <td>0.032513</td>\n",
       "      <td>0.014682</td>\n",
       "      <td>0.008828</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-05-31</th>\n",
       "      <td>0.032633</td>\n",
       "      <td>0.033800</td>\n",
       "      <td>0.050758</td>\n",
       "      <td>0.038244</td>\n",
       "      <td>0.021954</td>\n",
       "      <td>-0.014245</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-08-31</th>\n",
       "      <td>-0.041159</td>\n",
       "      <td>-0.039789</td>\n",
       "      <td>-0.034078</td>\n",
       "      <td>-0.021872</td>\n",
       "      <td>-0.041715</td>\n",
       "      <td>-0.066688</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-30</th>\n",
       "      <td>0.198623</td>\n",
       "      <td>0.224225</td>\n",
       "      <td>0.265612</td>\n",
       "      <td>0.166173</td>\n",
       "      <td>0.222903</td>\n",
       "      <td>0.243758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-10-31</th>\n",
       "      <td>0.012293</td>\n",
       "      <td>0.062672</td>\n",
       "      <td>0.142856</td>\n",
       "      <td>-0.045343</td>\n",
       "      <td>-0.007602</td>\n",
       "      <td>0.100149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-11-30</th>\n",
       "      <td>0.063139</td>\n",
       "      <td>0.054914</td>\n",
       "      <td>0.030768</td>\n",
       "      <td>0.001966</td>\n",
       "      <td>0.008327</td>\n",
       "      <td>-0.002971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-12-31</th>\n",
       "      <td>-0.017033</td>\n",
       "      <td>-0.025789</td>\n",
       "      <td>-0.080801</td>\n",
       "      <td>0.027283</td>\n",
       "      <td>-0.022770</td>\n",
       "      <td>-0.079669</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>299 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  SV        SM        SG        BV        BM        BG\n",
       "month                                                                 \n",
       "2000-01-31  0.111051  0.135348  0.167612  0.104549  0.184193  0.168754\n",
       "2000-02-29  0.124971  0.139342  0.146752  0.062845  0.109953  0.159660\n",
       "2000-03-31  0.111485  0.089074  0.123222  0.038707  0.017311  0.019475\n",
       "2000-04-30  0.020844  0.019261  0.015617  0.032513  0.014682  0.008828\n",
       "2000-05-31  0.032633  0.033800  0.050758  0.038244  0.021954 -0.014245\n",
       "...              ...       ...       ...       ...       ...       ...\n",
       "2024-08-31 -0.041159 -0.039789 -0.034078 -0.021872 -0.041715 -0.066688\n",
       "2024-09-30  0.198623  0.224225  0.265612  0.166173  0.222903  0.243758\n",
       "2024-10-31  0.012293  0.062672  0.142856 -0.045343 -0.007602  0.100149\n",
       "2024-11-30  0.063139  0.054914  0.030768  0.001966  0.008327 -0.002971\n",
       "2024-12-31 -0.017033 -0.025789 -0.080801  0.027283 -0.022770 -0.079669\n",
       "\n",
       "[299 rows x 6 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 改进后的代码\n",
    "def weighted_ret(group):\n",
    "    return np.average(group['next_ret'], weights=group['totalvalue'])\n",
    "\n",
    "def calc_portfolio_returns(data):\n",
    "    portfolios = {}\n",
    "    for size in ['S', 'B']:\n",
    "        for value in ['V', 'M', 'G']:\n",
    "            mask = (data['size'] == size) & (data['value'] == value)\n",
    "            port_name = f'{size}{value}'\n",
    "            portfolios[port_name] = (data[mask]\n",
    "                                   .groupby('month')\n",
    "                                   .apply(weighted_ret)\n",
    "                                   .to_frame(name=port_name))\n",
    "    return pd.concat(portfolios.values(), axis=1)\n",
    "    \n",
    "six_portfolio = calc_portfolio_returns(cross_new)\n",
    "# index is month and plus one month\n",
    "six_portfolio.index = six_portfolio.index + MonthEnd(1)\n",
    "six_portfolio = six_portfolio['2010-01':]\n",
    "six_portfolio"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c982e3c",
   "metadata": {},
   "source": [
    "Size Factor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "f865d7c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SMB</th>\n",
       "      <th>HML</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2000-01-31</th>\n",
       "      <td>-0.014495</td>\n",
       "      <td>-0.060382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-02-29</th>\n",
       "      <td>0.026202</td>\n",
       "      <td>-0.059298</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-03-31</th>\n",
       "      <td>0.082763</td>\n",
       "      <td>0.003747</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-04-30</th>\n",
       "      <td>-0.000101</td>\n",
       "      <td>0.014456</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-05-31</th>\n",
       "      <td>0.023746</td>\n",
       "      <td>0.017182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-08-31</th>\n",
       "      <td>0.005083</td>\n",
       "      <td>0.018868</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-30</th>\n",
       "      <td>0.018542</td>\n",
       "      <td>-0.072287</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-10-31</th>\n",
       "      <td>0.056873</td>\n",
       "      <td>-0.138028</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-11-30</th>\n",
       "      <td>0.047166</td>\n",
       "      <td>0.018654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-12-31</th>\n",
       "      <td>-0.016156</td>\n",
       "      <td>0.085360</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>299 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 SMB       HML\n",
       "month                         \n",
       "2000-01-31 -0.014495 -0.060382\n",
       "2000-02-29  0.026202 -0.059298\n",
       "2000-03-31  0.082763  0.003747\n",
       "2000-04-30 -0.000101  0.014456\n",
       "2000-05-31  0.023746  0.017182\n",
       "...              ...       ...\n",
       "2024-08-31  0.005083  0.018868\n",
       "2024-09-30  0.018542 -0.072287\n",
       "2024-10-31  0.056873 -0.138028\n",
       "2024-11-30  0.047166  0.018654\n",
       "2024-12-31 -0.016156  0.085360\n",
       "\n",
       "[299 rows x 2 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def calc_factors(portfolios):\n",
    "    # SMB因子\n",
    "    smb = ((portfolios['SV'] + portfolios['SM'] + portfolios['SG'])/3 - \n",
    "           (portfolios['BV'] + portfolios['BM'] + portfolios['BG'])/3)\n",
    "    \n",
    "    # HML因子\n",
    "    hml = ((portfolios['SV'] + portfolios['BV'])/2 - \n",
    "           (portfolios['SG'] + portfolios['BG'])/2)\n",
    "    \n",
    "    return pd.DataFrame({\n",
    "        'SMB': smb,\n",
    "        'HML': hml\n",
    "    })\n",
    "\n",
    "factors = calc_factors(six_portfolio)\n",
    "factors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a219fc73",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MKT</th>\n",
       "      <th>SMB</th>\n",
       "      <th>HML</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2000-01-31</th>\n",
       "      <td>0.158982</td>\n",
       "      <td>-0.014495</td>\n",
       "      <td>-0.060382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-02-29</th>\n",
       "      <td>0.120168</td>\n",
       "      <td>0.026202</td>\n",
       "      <td>-0.059298</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-03-31</th>\n",
       "      <td>0.054070</td>\n",
       "      <td>0.082763</td>\n",
       "      <td>0.003747</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-04-30</th>\n",
       "      <td>0.011158</td>\n",
       "      <td>-0.000101</td>\n",
       "      <td>0.014456</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-05-31</th>\n",
       "      <td>0.025835</td>\n",
       "      <td>0.023746</td>\n",
       "      <td>0.017182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-08-31</th>\n",
       "      <td>-0.032586</td>\n",
       "      <td>0.005083</td>\n",
       "      <td>0.018868</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-30</th>\n",
       "      <td>0.194874</td>\n",
       "      <td>0.018542</td>\n",
       "      <td>-0.072287</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-10-31</th>\n",
       "      <td>-0.004527</td>\n",
       "      <td>0.056873</td>\n",
       "      <td>-0.138028</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-11-30</th>\n",
       "      <td>0.008606</td>\n",
       "      <td>0.047166</td>\n",
       "      <td>0.018654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-12-31</th>\n",
       "      <td>-0.003797</td>\n",
       "      <td>-0.016156</td>\n",
       "      <td>0.085360</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>299 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 MKT       SMB       HML\n",
       "month                                   \n",
       "2000-01-31  0.158982 -0.014495 -0.060382\n",
       "2000-02-29  0.120168  0.026202 -0.059298\n",
       "2000-03-31  0.054070  0.082763  0.003747\n",
       "2000-04-30  0.011158 -0.000101  0.014456\n",
       "2000-05-31  0.025835  0.023746  0.017182\n",
       "...              ...       ...       ...\n",
       "2024-08-31 -0.032586  0.005083  0.018868\n",
       "2024-09-30  0.194874  0.018542 -0.072287\n",
       "2024-10-31 -0.004527  0.056873 -0.138028\n",
       "2024-11-30  0.008606  0.047166  0.018654\n",
       "2024-12-31 -0.003797 -0.016156  0.085360\n",
       "\n",
       "[299 rows x 3 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factors = pd.merge(factors, Market_ret[['MKT']], left_index=True, right_index=True, how='left')\n",
    "factors = factors[['MKT','SMB','HML']]\n",
    "factors\n",
    "factors.to_csv('D:/笃行楼209/factors_3f.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "3fdb1039",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x1e376fdb5b0>]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1e376fda410>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"716pt\" height=\"362.165pt\" viewBox=\"0 0 716 362.165\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:date>2025-12-01T20:37:25.352756</dc:date>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Matplotlib v3.7.0, https://matplotlib.org/</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 362.165 \n",
       "L 716 362.165 \n",
       "L 716 0 \n",
       "L 0 0 \n",
       "z\n",
       "\" style=\"fill: #ffffff\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 39.2 339.84 \n",
       "L 708.8 339.84 \n",
       "L 708.8 7.2 \n",
       "L 39.2 7.2 \n",
       "z\n",
       "\" style=\"fill: #ffffff\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <defs>\n",
       "       <path id=\"m8fc4c80f4f\" d=\"M 0 0 \n",
       "L 0 3.5 \n",
       "\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8fc4c80f4f\" x=\"67.629791\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_1\">\n",
       "      <!-- 2000 -->\n",
       "      <g transform=\"translate(57.629791 353.715) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-32\" d=\"M 300 250 \n",
       "Q 325 625 650 925 \n",
       "Q 975 1225 1475 1862 \n",
       "Q 1975 2500 2125 2850 \n",
       "Q 2275 3200 2237 3450 \n",
       "Q 2200 3700 2000 3862 \n",
       "Q 1800 4025 1537 4000 \n",
       "Q 1275 3975 1037 3800 \n",
       "Q 800 3625 675 3275 \n",
       "L 200 3350 \n",
       "Q 400 3925 712 4187 \n",
       "Q 1025 4450 1450 4475 \n",
       "Q 1700 4500 1900 4462 \n",
       "Q 2100 4425 2312 4287 \n",
       "Q 2525 4150 2662 3875 \n",
       "Q 2800 3600 2762 3212 \n",
       "Q 2725 2825 2375 2287 \n",
       "Q 2025 1750 1025 600 \n",
       "L 2825 600 \n",
       "L 2825 150 \n",
       "L 300 150 \n",
       "L 300 250 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"SimHei-30\" d=\"M 225 2537 \n",
       "Q 250 3200 412 3587 \n",
       "Q 575 3975 875 4225 \n",
       "Q 1175 4475 1612 4475 \n",
       "Q 2050 4475 2375 4112 \n",
       "Q 2700 3750 2800 3200 \n",
       "Q 2900 2650 2862 1937 \n",
       "Q 2825 1225 2612 775 \n",
       "Q 2400 325 1975 150 \n",
       "Q 1550 -25 1125 187 \n",
       "Q 700 400 525 750 \n",
       "Q 350 1100 275 1487 \n",
       "Q 200 1875 225 2537 \n",
       "z\n",
       "M 750 2687 \n",
       "Q 675 2000 800 1462 \n",
       "Q 925 925 1212 700 \n",
       "Q 1500 475 1800 612 \n",
       "Q 2100 750 2237 1162 \n",
       "Q 2375 1575 2375 2062 \n",
       "Q 2375 2550 2337 2950 \n",
       "Q 2300 3350 2112 3675 \n",
       "Q 1925 4000 1612 4012 \n",
       "Q 1300 4025 1062 3700 \n",
       "Q 825 3375 750 2687 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_2\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8fc4c80f4f\" x=\"165.349882\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_2\">\n",
       "      <!-- 2004 -->\n",
       "      <g transform=\"translate(155.349882 353.715) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-34\" d=\"M 2000 1100 \n",
       "L 75 1100 \n",
       "L 75 1525 \n",
       "L 2100 4450 \n",
       "L 2475 4450 \n",
       "L 2475 1525 \n",
       "L 3075 1525 \n",
       "L 3075 1100 \n",
       "L 2475 1100 \n",
       "L 2475 150 \n",
       "L 2000 150 \n",
       "L 2000 1100 \n",
       "z\n",
       "M 2000 1525 \n",
       "L 2000 3500 \n",
       "L 600 1525 \n",
       "L 2000 1525 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-34\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8fc4c80f4f\" x=\"263.069972\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_3\">\n",
       "      <!-- 2008 -->\n",
       "      <g transform=\"translate(253.069972 353.715) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-38\" d=\"M 175 1375 \n",
       "Q 175 1675 325 1962 \n",
       "Q 475 2250 825 2425 \n",
       "Q 525 2600 425 2812 \n",
       "Q 325 3025 312 3300 \n",
       "Q 300 3575 387 3775 \n",
       "Q 475 3975 650 4150 \n",
       "Q 825 4325 1037 4387 \n",
       "Q 1250 4450 1500 4450 \n",
       "Q 1750 4450 1950 4400 \n",
       "Q 2150 4350 2375 4187 \n",
       "Q 2600 4025 2700 3725 \n",
       "Q 2800 3425 2687 3025 \n",
       "Q 2575 2625 2100 2400 \n",
       "Q 2525 2275 2700 2012 \n",
       "Q 2875 1750 2875 1375 \n",
       "Q 2875 1000 2762 775 \n",
       "Q 2650 550 2512 400 \n",
       "Q 2375 250 2137 162 \n",
       "Q 1900 75 1537 75 \n",
       "Q 1175 75 912 162 \n",
       "Q 650 250 475 425 \n",
       "Q 300 600 237 837 \n",
       "Q 175 1075 175 1375 \n",
       "z\n",
       "M 687 1400 \n",
       "Q 675 1100 787 875 \n",
       "Q 900 650 1200 587 \n",
       "Q 1500 525 1825 600 \n",
       "Q 2150 675 2275 950 \n",
       "Q 2400 1225 2362 1500 \n",
       "Q 2325 1775 2050 1962 \n",
       "Q 1775 2150 1450 2125 \n",
       "Q 1125 2100 912 1900 \n",
       "Q 700 1700 687 1400 \n",
       "z\n",
       "M 775 3350 \n",
       "Q 775 3100 950 2875 \n",
       "Q 1125 2650 1500 2650 \n",
       "Q 1875 2650 2062 2875 \n",
       "Q 2250 3100 2237 3412 \n",
       "Q 2225 3725 2012 3875 \n",
       "Q 1800 4025 1437 4000 \n",
       "Q 1075 3975 925 3787 \n",
       "Q 775 3600 775 3350 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-38\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_4\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8fc4c80f4f\" x=\"360.790063\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_4\">\n",
       "      <!-- 2012 -->\n",
       "      <g transform=\"translate(350.790063 353.715) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-31\" d=\"M 1400 3600 \n",
       "Q 1075 3275 575 2975 \n",
       "L 575 3450 \n",
       "Q 1200 3875 1600 4450 \n",
       "L 1900 4450 \n",
       "L 1900 150 \n",
       "L 1400 150 \n",
       "L 1400 3600 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8fc4c80f4f\" x=\"458.510154\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_5\">\n",
       "      <!-- 2016 -->\n",
       "      <g transform=\"translate(448.510154 353.715) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-36\" d=\"M 250 1612 \n",
       "Q 275 1975 387 2225 \n",
       "Q 500 2475 725 2850 \n",
       "L 1750 4450 \n",
       "L 2325 4450 \n",
       "L 1275 2800 \n",
       "Q 1950 2975 2350 2750 \n",
       "Q 2750 2525 2887 2237 \n",
       "Q 3025 1950 3037 1612 \n",
       "Q 3050 1275 2937 950 \n",
       "Q 2825 625 2537 362 \n",
       "Q 2250 100 1737 75 \n",
       "Q 1225 50 862 262 \n",
       "Q 500 475 362 862 \n",
       "Q 225 1250 250 1612 \n",
       "z\n",
       "M 1025 787 \n",
       "Q 1250 550 1625 525 \n",
       "Q 2000 500 2250 775 \n",
       "Q 2500 1050 2500 1575 \n",
       "Q 2500 2100 2187 2300 \n",
       "Q 1875 2500 1487 2450 \n",
       "Q 1100 2400 925 2075 \n",
       "Q 750 1750 775 1387 \n",
       "Q 800 1025 1025 787 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-36\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_6\">\n",
       "     <g id=\"line2d_6\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8fc4c80f4f\" x=\"556.230244\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_6\">\n",
       "      <!-- 2020 -->\n",
       "      <g transform=\"translate(546.230244 353.715) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_7\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8fc4c80f4f\" x=\"653.950335\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_7\">\n",
       "      <!-- 2024 -->\n",
       "      <g transform=\"translate(643.950335 353.715) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-34\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_8\">\n",
       "      <defs>\n",
       "       <path id=\"m8a59d573ed\" d=\"M 0 0 \n",
       "L -3.5 0 \n",
       "\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8a59d573ed\" x=\"39.2\" y=\"296.23881\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_8\">\n",
       "      <!-- -0.15 -->\n",
       "      <g transform=\"translate(7.2 299.67631) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-2d\" d=\"M 2975 2125 \n",
       "L 125 2125 \n",
       "L 125 2525 \n",
       "L 2975 2525 \n",
       "L 2975 2125 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"SimHei-2e\" d=\"M 1075 125 \n",
       "L 500 125 \n",
       "L 500 675 \n",
       "L 1075 675 \n",
       "L 1075 125 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"SimHei-35\" d=\"M 550 1325 \n",
       "Q 725 650 1150 575 \n",
       "Q 1575 500 1837 662 \n",
       "Q 2100 825 2212 1087 \n",
       "Q 2325 1350 2312 1675 \n",
       "Q 2300 2000 2137 2225 \n",
       "Q 1975 2450 1725 2525 \n",
       "Q 1475 2600 1162 2525 \n",
       "Q 850 2450 650 2175 \n",
       "L 225 2225 \n",
       "Q 275 2375 700 4375 \n",
       "L 2675 4375 \n",
       "L 2675 3925 \n",
       "L 1075 3925 \n",
       "Q 950 3250 825 2850 \n",
       "Q 1200 3025 1525 3012 \n",
       "Q 1850 3000 2150 2862 \n",
       "Q 2450 2725 2587 2487 \n",
       "Q 2725 2250 2787 2012 \n",
       "Q 2850 1775 2837 1500 \n",
       "Q 2825 1225 2725 937 \n",
       "Q 2625 650 2425 462 \n",
       "Q 2225 275 1937 162 \n",
       "Q 1650 50 1275 75 \n",
       "Q 900 100 562 350 \n",
       "Q 225 600 100 1200 \n",
       "L 550 1325 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-2d\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"150\"/>\n",
       "       <use xlink:href=\"#SimHei-35\" x=\"200\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8a59d573ed\" x=\"39.2\" y=\"251.785638\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_9\">\n",
       "      <!-- -0.10 -->\n",
       "      <g transform=\"translate(7.2 255.223138) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-2d\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"150\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"200\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_10\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8a59d573ed\" x=\"39.2\" y=\"207.332466\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_10\">\n",
       "      <!-- -0.05 -->\n",
       "      <g transform=\"translate(7.2 210.769966) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-2d\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "       <use xlink:href=\"#SimHei-35\" x=\"200\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8a59d573ed\" x=\"39.2\" y=\"162.879294\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_11\">\n",
       "      <!-- 0.00 -->\n",
       "      <g transform=\"translate(12.2 166.316794) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-30\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_12\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8a59d573ed\" x=\"39.2\" y=\"118.426122\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_12\">\n",
       "      <!-- 0.05 -->\n",
       "      <g transform=\"translate(12.2 121.863622) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-30\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-35\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_13\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8a59d573ed\" x=\"39.2\" y=\"73.97295\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_13\">\n",
       "      <!-- 0.10 -->\n",
       "      <g transform=\"translate(12.2 77.41045) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-30\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_7\">\n",
       "     <g id=\"line2d_14\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8a59d573ed\" x=\"39.2\" y=\"29.519778\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_14\">\n",
       "      <!-- 0.15 -->\n",
       "      <g transform=\"translate(12.2 32.957278) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-30\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-35\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_15\">\n",
       "    <path d=\"M 69.636364 175.766313 \n",
       "L 71.576051 139.583703 \n",
       "L 73.649509 89.298163 \n",
       "L 75.656082 162.968664 \n",
       "L 77.72954 141.767508 \n",
       "L 79.736113 154.359279 \n",
       "L 81.809571 150.346158 \n",
       "L 83.88303 143.997417 \n",
       "L 85.889603 150.125779 \n",
       "L 87.963061 136.76957 \n",
       "L 89.969634 151.976288 \n",
       "L 92.043092 145.532161 \n",
       "L 95.989352 169.430152 \n",
       "L 98.06281 151.118718 \n",
       "L 100.069383 155.453271 \n",
       "L 102.142841 137.144327 \n",
       "L 104.149414 147.606245 \n",
       "L 106.222873 167.235696 \n",
       "L 108.296331 156.047326 \n",
       "L 110.302904 174.517028 \n",
       "L 112.376362 172.09185 \n",
       "L 114.382935 142.145932 \n",
       "L 116.456393 175.34972 \n",
       "L 118.529852 199.084204 \n",
       "L 120.402653 141.7328 \n",
       "L 124.482684 149.715985 \n",
       "L 126.556143 174.755153 \n",
       "L 128.562715 186.039381 \n",
       "L 130.636174 151.27486 \n",
       "L 132.709632 163.567526 \n",
       "L 134.716205 169.528522 \n",
       "L 136.789663 172.335008 \n",
       "L 138.796236 194.075785 \n",
       "L 140.869695 167.421289 \n",
       "L 142.943153 146.939439 \n",
       "L 144.815954 155.904204 \n",
       "L 146.889413 193.032539 \n",
       "L 148.895985 214.592194 \n",
       "L 150.969444 171.197205 \n",
       "L 152.976017 165.52662 \n",
       "L 155.049475 192.185131 \n",
       "L 157.122934 151.310263 \n",
       "L 159.129506 161.436806 \n",
       "L 161.202965 199.361811 \n",
       "L 163.209537 156.127443 \n",
       "L 165.282996 220.234451 \n",
       "L 167.356454 124.43013 \n",
       "L 169.296141 127.47727 \n",
       "L 171.3696 148.693854 \n",
       "L 173.376172 149.059534 \n",
       "L 175.449631 155.993363 \n",
       "L 177.456204 182.385608 \n",
       "L 179.529662 181.076694 \n",
       "L 181.603121 161.123796 \n",
       "L 183.609693 158.97273 \n",
       "L 185.683152 169.814099 \n",
       "L 187.689724 131.205124 \n",
       "L 189.763183 171.874509 \n",
       "L 191.836641 169.737473 \n",
       "L 193.709443 147.308729 \n",
       "L 195.782901 190.817746 \n",
       "L 197.789474 210.093235 \n",
       "L 199.862932 116.952133 \n",
       "L 201.869505 179.855237 \n",
       "L 203.942963 224.594929 \n",
       "L 206.016422 91.984461 \n",
       "L 208.022994 136.427109 \n",
       "L 210.096453 173.213655 \n",
       "L 212.103026 152.402317 \n",
       "L 214.176484 201.959298 \n",
       "L 216.249943 165.520076 \n",
       "L 218.122744 168.232188 \n",
       "L 220.196202 170.641299 \n",
       "L 222.202775 197.666239 \n",
       "L 224.276233 60.015582 \n",
       "L 226.282806 122.97241 \n",
       "L 228.356265 127.641604 \n",
       "L 230.429723 172.086871 \n",
       "L 232.436296 178.30468 \n",
       "L 234.509754 177.74804 \n",
       "L 236.516327 256.740528 \n",
       "L 238.589785 255.031184 \n",
       "L 240.663244 91.613878 \n",
       "L 242.536045 51.623475 \n",
       "L 244.609503 94.06684 \n",
       "L 246.616076 111.500237 \n",
       "L 248.689535 190.595825 \n",
       "L 250.696107 219.206646 \n",
       "L 252.769566 103.433615 \n",
       "L 254.843024 197.269083 \n",
       "L 256.849597 171.339831 \n",
       "L 258.923055 256.140372 \n",
       "L 260.929628 69.887483 \n",
       "L 263.003087 107.912643 \n",
       "L 267.016232 88.018126 \n",
       "L 271.096263 224.542401 \n",
       "L 273.169722 125.680505 \n",
       "L 275.176294 206.959438 \n",
       "L 277.249753 96.80401 \n",
       "L 279.323211 208.758633 \n",
       "L 281.329784 203.378219 \n",
       "L 283.403242 155.933631 \n",
       "L 285.409815 42.806913 \n",
       "L 287.483274 109.810466 \n",
       "L 289.556732 90.131289 \n",
       "L 291.429533 136.325034 \n",
       "L 293.502992 111.94709 \n",
       "L 295.509564 137.422052 \n",
       "L 297.583023 144.776124 \n",
       "L 299.589596 233.19052 \n",
       "L 301.663054 209.267369 \n",
       "L 303.736512 87.460203 \n",
       "L 305.743085 169.677964 \n",
       "L 309.823116 85.591846 \n",
       "L 311.896575 144.58646 \n",
       "L 313.970033 89.744232 \n",
       "L 315.842834 134.213587 \n",
       "L 317.916293 143.512764 \n",
       "L 319.922866 157.01492 \n",
       "L 321.996324 163.306041 \n",
       "L 324.002897 168.72148 \n",
       "L 326.076355 119.578246 \n",
       "L 328.149814 115.187763 \n",
       "L 330.156386 180.218863 \n",
       "L 332.229845 195.555264 \n",
       "L 334.236418 122.084767 \n",
       "L 336.309876 175.943094 \n",
       "L 338.383334 162.853759 \n",
       "L 340.256136 128.876566 \n",
       "L 342.329594 153.592754 \n",
       "L 344.336167 170.951194 \n",
       "L 346.409625 166.209806 \n",
       "L 348.416198 158.865647 \n",
       "L 350.489656 146.929569 \n",
       "L 352.563115 151.292917 \n",
       "L 354.569688 177.951843 \n",
       "L 356.643146 161.623799 \n",
       "L 358.649719 158.267706 \n",
       "L 360.723177 214.942211 \n",
       "L 362.796636 178.310962 \n",
       "L 364.736323 114.894641 \n",
       "L 366.809781 165.339631 \n",
       "L 368.816354 141.328879 \n",
       "L 372.896385 176.754993 \n",
       "L 374.969843 196.153714 \n",
       "L 377.043302 110.447383 \n",
       "L 379.049875 181.139562 \n",
       "L 381.123333 150.755474 \n",
       "L 383.129906 198.916871 \n",
       "L 385.203364 156.095488 \n",
       "L 387.276823 145.935701 \n",
       "L 389.149624 140.0046 \n",
       "L 391.223082 150.970237 \n",
       "L 393.229655 169.688773 \n",
       "L 395.303114 113.850209 \n",
       "L 397.309686 184.692874 \n",
       "L 399.383145 134.333654 \n",
       "L 401.456603 125.437709 \n",
       "L 403.463176 171.379846 \n",
       "L 405.536634 145.343899 \n",
       "L 407.543207 130.556443 \n",
       "L 409.616666 145.306446 \n",
       "L 411.690124 135.000925 \n",
       "L 413.562925 124.533871 \n",
       "L 415.636384 145.282903 \n",
       "L 417.642956 175.575566 \n",
       "L 419.716415 151.949477 \n",
       "L 421.722987 140.949507 \n",
       "L 423.796446 149.502041 \n",
       "L 425.869904 138.224081 \n",
       "L 427.876477 118.294459 \n",
       "L 429.949936 156.816656 \n",
       "L 431.956508 180.04804 \n",
       "L 434.029967 324.72 \n",
       "L 436.103425 97.673326 \n",
       "L 437.976226 151.721035 \n",
       "L 440.049685 91.195113 \n",
       "L 442.056258 169.60206 \n",
       "L 444.129716 22.32 \n",
       "L 446.136289 178.707603 \n",
       "L 448.209747 194.030352 \n",
       "L 450.283206 155.208548 \n",
       "L 452.289778 134.05778 \n",
       "L 454.363237 94.690306 \n",
       "L 456.36981 90.692915 \n",
       "L 458.443268 122.068527 \n",
       "L 460.516726 198.841046 \n",
       "L 462.456413 164.730365 \n",
       "L 464.529872 112.201822 \n",
       "L 466.536445 144.452478 \n",
       "L 468.609903 168.732547 \n",
       "L 470.616476 122.483979 \n",
       "L 472.689934 171.484684 \n",
       "L 474.763393 153.306822 \n",
       "L 476.769965 151.744107 \n",
       "L 478.843424 150.584985 \n",
       "L 480.849997 177.291851 \n",
       "L 482.923455 162.531462 \n",
       "L 484.996913 192.504335 \n",
       "L 486.869715 150.928846 \n",
       "L 488.943173 169.145799 \n",
       "L 490.949746 194.105048 \n",
       "L 493.023204 207.321026 \n",
       "L 495.029777 162.339061 \n",
       "L 497.103235 175.397741 \n",
       "L 499.176694 165.111003 \n",
       "L 501.183267 157.835982 \n",
       "L 503.256725 196.553804 \n",
       "L 505.263298 195.487894 \n",
       "L 507.336756 181.471912 \n",
       "L 509.410215 209.696004 \n",
       "L 511.283016 164.598225 \n",
       "L 513.356474 127.851355 \n",
       "L 515.363047 175.575503 \n",
       "L 517.436505 182.765033 \n",
       "L 519.443078 195.802038 \n",
       "L 521.516537 159.332241 \n",
       "L 523.589995 182.05364 \n",
       "L 525.596568 189.247625 \n",
       "L 527.670026 169.040954 \n",
       "L 529.676599 117.259849 \n",
       "L 531.750057 168.839908 \n",
       "L 533.823516 207.535773 \n",
       "L 535.696317 114.024167 \n",
       "L 537.769776 126.565196 \n",
       "L 539.776348 183.579558 \n",
       "L 541.849807 149.368893 \n",
       "L 543.856379 191.937486 \n",
       "L 545.929838 189.09135 \n",
       "L 548.003296 176.978511 \n",
       "L 550.009869 154.279199 \n",
       "L 552.083328 181.87935 \n",
       "L 554.0899 173.112376 \n",
       "L 556.163359 152.803417 \n",
       "L 558.236817 164.908064 \n",
       "L 560.176504 164.098949 \n",
       "L 562.249963 132.149037 \n",
       "L 564.256535 201.671471 \n",
       "L 566.329994 150.948497 \n",
       "L 568.336566 188.700042 \n",
       "L 570.410025 161.041601 \n",
       "L 572.483483 141.315656 \n",
       "L 574.490056 182.021053 \n",
       "L 576.563514 180.519002 \n",
       "L 578.570087 178.202413 \n",
       "L 580.643546 242.223789 \n",
       "L 582.717004 251.331217 \n",
       "L 584.589805 117.165525 \n",
       "L 586.663264 110.5751 \n",
       "L 588.669836 191.674272 \n",
       "L 590.743295 157.597931 \n",
       "L 592.749868 149.397448 \n",
       "L 594.823326 118.874709 \n",
       "L 596.896785 127.980873 \n",
       "L 598.903357 169.051414 \n",
       "L 600.976816 195.132747 \n",
       "L 602.983388 65.241494 \n",
       "L 605.056847 125.213915 \n",
       "L 607.130305 164.92765 \n",
       "L 609.003107 134.412926 \n",
       "L 611.076565 125.008123 \n",
       "L 613.083138 235.252908 \n",
       "L 615.156596 110.164093 \n",
       "L 617.163169 182.351975 \n",
       "L 619.236627 101.741845 \n",
       "L 621.310086 169.856008 \n",
       "L 623.316659 185.236588 \n",
       "L 625.390117 98.711556 \n",
       "L 627.39669 156.562986 \n",
       "L 629.470148 180.685184 \n",
       "L 631.543607 151.070056 \n",
       "L 633.416408 127.447315 \n",
       "L 635.489866 179.19944 \n",
       "L 637.496439 186.34745 \n",
       "L 639.569897 131.178154 \n",
       "L 641.57647 143.862406 \n",
       "L 643.649929 179.566426 \n",
       "L 645.723387 153.606383 \n",
       "L 647.72996 149.038505 \n",
       "L 649.803418 150.373099 \n",
       "L 651.809991 124.515888 \n",
       "L 653.883449 163.741222 \n",
       "L 655.956908 229.547943 \n",
       "L 657.896595 209.342432 \n",
       "L 659.970053 122.923008 \n",
       "L 661.976626 189.438339 \n",
       "L 664.050084 163.417199 \n",
       "L 666.056657 209.491812 \n",
       "L 668.130116 163.036578 \n",
       "L 670.203574 158.360055 \n",
       "L 672.210147 146.394232 \n",
       "L 674.283605 112.316021 \n",
       "L 676.290178 120.945285 \n",
       "L 678.363636 177.242681 \n",
       "L 678.363636 177.242681 \n",
       "\" clip-path=\"url(#p24986abf4f)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 39.2 339.84 \n",
       "L 39.2 7.2 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 708.8 339.84 \n",
       "L 708.8 7.2 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 39.2 339.84 \n",
       "L 708.8 339.84 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path d=\"M 39.2 7.2 \n",
       "L 708.8 7.2 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"legend_1\">\n",
       "    <g id=\"patch_7\">\n",
       "     <path d=\"M 46.2 28.45 \n",
       "L 93.2 28.45 \n",
       "Q 95.2 28.45 95.2 26.45 \n",
       "L 95.2 14.2 \n",
       "Q 95.2 12.2 93.2 12.2 \n",
       "L 46.2 12.2 \n",
       "Q 44.2 12.2 44.2 14.2 \n",
       "L 44.2 26.45 \n",
       "Q 44.2 28.45 46.2 28.45 \n",
       "z\n",
       "\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n",
       "    </g>\n",
       "    <g id=\"line2d_16\">\n",
       "     <path d=\"M 48.2 19.7 \n",
       "L 58.2 19.7 \n",
       "L 68.2 19.7 \n",
       "\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "    </g>\n",
       "    <g id=\"text_15\">\n",
       "     <!-- SMB -->\n",
       "     <g transform=\"translate(76.2 23.2) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"SimHei-53\" d=\"M 2900 1325 \n",
       "Q 2900 750 2537 412 \n",
       "Q 2175 75 1550 75 \n",
       "Q 925 75 575 425 \n",
       "Q 225 775 225 1300 \n",
       "L 225 1475 \n",
       "L 800 1475 \n",
       "L 800 1325 \n",
       "Q 800 950 1025 750 \n",
       "Q 1250 550 1550 550 \n",
       "Q 1950 550 2137 762 \n",
       "Q 2325 975 2325 1275 \n",
       "Q 2325 1525 2100 1737 \n",
       "Q 1875 1950 1450 2125 \n",
       "Q 850 2350 587 2625 \n",
       "Q 325 2900 325 3275 \n",
       "Q 325 3800 687 4125 \n",
       "Q 1050 4450 1550 4450 \n",
       "Q 2200 4450 2487 4062 \n",
       "Q 2775 3675 2775 3225 \n",
       "L 2200 3225 \n",
       "Q 2225 3500 2050 3725 \n",
       "Q 1875 3950 1550 3950 \n",
       "Q 1250 3950 1075 3787 \n",
       "Q 900 3625 900 3350 \n",
       "Q 900 3125 1037 2962 \n",
       "Q 1175 2800 1750 2575 \n",
       "Q 2300 2350 2600 2037 \n",
       "Q 2900 1725 2900 1325 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"SimHei-4d\" d=\"M 2925 125 \n",
       "L 2425 125 \n",
       "L 2425 3175 \n",
       "L 2375 3175 \n",
       "L 1775 125 \n",
       "L 1375 125 \n",
       "L 775 3175 \n",
       "L 725 3175 \n",
       "L 725 125 \n",
       "L 225 125 \n",
       "L 225 4400 \n",
       "L 1000 4400 \n",
       "L 1550 1575 \n",
       "L 1600 1575 \n",
       "L 2150 4400 \n",
       "L 2925 4400 \n",
       "L 2925 125 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"SimHei-42\" d=\"M 2950 1400 \n",
       "Q 2950 675 2550 400 \n",
       "Q 2150 125 1525 125 \n",
       "L 275 125 \n",
       "L 275 4400 \n",
       "L 1575 4400 \n",
       "Q 2200 4400 2512 4075 \n",
       "Q 2825 3750 2825 3300 \n",
       "Q 2825 2850 2612 2637 \n",
       "Q 2400 2425 2175 2350 \n",
       "Q 2475 2275 2712 2037 \n",
       "Q 2950 1800 2950 1400 \n",
       "z\n",
       "M 2250 3300 \n",
       "Q 2250 3625 2062 3775 \n",
       "Q 1875 3925 1600 3925 \n",
       "L 850 3925 \n",
       "L 850 2600 \n",
       "L 1575 2600 \n",
       "Q 1850 2600 2050 2762 \n",
       "Q 2250 2925 2250 3300 \n",
       "z\n",
       "M 2350 1400 \n",
       "Q 2350 1800 2087 1962 \n",
       "Q 1825 2125 1500 2125 \n",
       "L 850 2125 \n",
       "L 850 600 \n",
       "L 1425 600 \n",
       "Q 1875 600 2112 775 \n",
       "Q 2350 950 2350 1400 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#SimHei-53\"/>\n",
       "      <use xlink:href=\"#SimHei-4d\" x=\"50\"/>\n",
       "      <use xlink:href=\"#SimHei-42\" x=\"100\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p24986abf4f\">\n",
       "   <rect x=\"39.2\" y=\"7.2\" width=\"669.6\" height=\"332.64\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<Figure size 1200x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot SMB\n",
    "fig = plt.figure(figsize=(12,6))\n",
    "plt.plot(factors['SMB'], label='SMB')\n",
    "plt.legend(loc='upper left')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f7ed507",
   "metadata": {},
   "source": [
    "Value Factor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "783dd6d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x1e37a55bdc0>]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1e32871cb80>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"716pt\" height=\"362.165pt\" viewBox=\"0 0 716 362.165\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:date>2025-12-01T20:37:29.130353</dc:date>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Matplotlib v3.7.0, https://matplotlib.org/</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 362.165 \n",
       "L 716 362.165 \n",
       "L 716 0 \n",
       "L 0 0 \n",
       "z\n",
       "\" style=\"fill: #ffffff\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 39.2 339.84 \n",
       "L 708.8 339.84 \n",
       "L 708.8 7.2 \n",
       "L 39.2 7.2 \n",
       "z\n",
       "\" style=\"fill: #ffffff\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <defs>\n",
       "       <path id=\"mb81aeef8cd\" d=\"M 0 0 \n",
       "L 0 3.5 \n",
       "\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#mb81aeef8cd\" x=\"67.629791\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_1\">\n",
       "      <!-- 2000 -->\n",
       "      <g transform=\"translate(57.629791 353.715) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-32\" d=\"M 300 250 \n",
       "Q 325 625 650 925 \n",
       "Q 975 1225 1475 1862 \n",
       "Q 1975 2500 2125 2850 \n",
       "Q 2275 3200 2237 3450 \n",
       "Q 2200 3700 2000 3862 \n",
       "Q 1800 4025 1537 4000 \n",
       "Q 1275 3975 1037 3800 \n",
       "Q 800 3625 675 3275 \n",
       "L 200 3350 \n",
       "Q 400 3925 712 4187 \n",
       "Q 1025 4450 1450 4475 \n",
       "Q 1700 4500 1900 4462 \n",
       "Q 2100 4425 2312 4287 \n",
       "Q 2525 4150 2662 3875 \n",
       "Q 2800 3600 2762 3212 \n",
       "Q 2725 2825 2375 2287 \n",
       "Q 2025 1750 1025 600 \n",
       "L 2825 600 \n",
       "L 2825 150 \n",
       "L 300 150 \n",
       "L 300 250 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"SimHei-30\" d=\"M 225 2537 \n",
       "Q 250 3200 412 3587 \n",
       "Q 575 3975 875 4225 \n",
       "Q 1175 4475 1612 4475 \n",
       "Q 2050 4475 2375 4112 \n",
       "Q 2700 3750 2800 3200 \n",
       "Q 2900 2650 2862 1937 \n",
       "Q 2825 1225 2612 775 \n",
       "Q 2400 325 1975 150 \n",
       "Q 1550 -25 1125 187 \n",
       "Q 700 400 525 750 \n",
       "Q 350 1100 275 1487 \n",
       "Q 200 1875 225 2537 \n",
       "z\n",
       "M 750 2687 \n",
       "Q 675 2000 800 1462 \n",
       "Q 925 925 1212 700 \n",
       "Q 1500 475 1800 612 \n",
       "Q 2100 750 2237 1162 \n",
       "Q 2375 1575 2375 2062 \n",
       "Q 2375 2550 2337 2950 \n",
       "Q 2300 3350 2112 3675 \n",
       "Q 1925 4000 1612 4012 \n",
       "Q 1300 4025 1062 3700 \n",
       "Q 825 3375 750 2687 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_2\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mb81aeef8cd\" x=\"165.349882\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_2\">\n",
       "      <!-- 2004 -->\n",
       "      <g transform=\"translate(155.349882 353.715) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-34\" d=\"M 2000 1100 \n",
       "L 75 1100 \n",
       "L 75 1525 \n",
       "L 2100 4450 \n",
       "L 2475 4450 \n",
       "L 2475 1525 \n",
       "L 3075 1525 \n",
       "L 3075 1100 \n",
       "L 2475 1100 \n",
       "L 2475 150 \n",
       "L 2000 150 \n",
       "L 2000 1100 \n",
       "z\n",
       "M 2000 1525 \n",
       "L 2000 3500 \n",
       "L 600 1525 \n",
       "L 2000 1525 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-34\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mb81aeef8cd\" x=\"263.069972\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_3\">\n",
       "      <!-- 2008 -->\n",
       "      <g transform=\"translate(253.069972 353.715) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-38\" d=\"M 175 1375 \n",
       "Q 175 1675 325 1962 \n",
       "Q 475 2250 825 2425 \n",
       "Q 525 2600 425 2812 \n",
       "Q 325 3025 312 3300 \n",
       "Q 300 3575 387 3775 \n",
       "Q 475 3975 650 4150 \n",
       "Q 825 4325 1037 4387 \n",
       "Q 1250 4450 1500 4450 \n",
       "Q 1750 4450 1950 4400 \n",
       "Q 2150 4350 2375 4187 \n",
       "Q 2600 4025 2700 3725 \n",
       "Q 2800 3425 2687 3025 \n",
       "Q 2575 2625 2100 2400 \n",
       "Q 2525 2275 2700 2012 \n",
       "Q 2875 1750 2875 1375 \n",
       "Q 2875 1000 2762 775 \n",
       "Q 2650 550 2512 400 \n",
       "Q 2375 250 2137 162 \n",
       "Q 1900 75 1537 75 \n",
       "Q 1175 75 912 162 \n",
       "Q 650 250 475 425 \n",
       "Q 300 600 237 837 \n",
       "Q 175 1075 175 1375 \n",
       "z\n",
       "M 687 1400 \n",
       "Q 675 1100 787 875 \n",
       "Q 900 650 1200 587 \n",
       "Q 1500 525 1825 600 \n",
       "Q 2150 675 2275 950 \n",
       "Q 2400 1225 2362 1500 \n",
       "Q 2325 1775 2050 1962 \n",
       "Q 1775 2150 1450 2125 \n",
       "Q 1125 2100 912 1900 \n",
       "Q 700 1700 687 1400 \n",
       "z\n",
       "M 775 3350 \n",
       "Q 775 3100 950 2875 \n",
       "Q 1125 2650 1500 2650 \n",
       "Q 1875 2650 2062 2875 \n",
       "Q 2250 3100 2237 3412 \n",
       "Q 2225 3725 2012 3875 \n",
       "Q 1800 4025 1437 4000 \n",
       "Q 1075 3975 925 3787 \n",
       "Q 775 3600 775 3350 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-38\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_4\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mb81aeef8cd\" x=\"360.790063\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_4\">\n",
       "      <!-- 2012 -->\n",
       "      <g transform=\"translate(350.790063 353.715) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-31\" d=\"M 1400 3600 \n",
       "Q 1075 3275 575 2975 \n",
       "L 575 3450 \n",
       "Q 1200 3875 1600 4450 \n",
       "L 1900 4450 \n",
       "L 1900 150 \n",
       "L 1400 150 \n",
       "L 1400 3600 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mb81aeef8cd\" x=\"458.510154\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_5\">\n",
       "      <!-- 2016 -->\n",
       "      <g transform=\"translate(448.510154 353.715) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-36\" d=\"M 250 1612 \n",
       "Q 275 1975 387 2225 \n",
       "Q 500 2475 725 2850 \n",
       "L 1750 4450 \n",
       "L 2325 4450 \n",
       "L 1275 2800 \n",
       "Q 1950 2975 2350 2750 \n",
       "Q 2750 2525 2887 2237 \n",
       "Q 3025 1950 3037 1612 \n",
       "Q 3050 1275 2937 950 \n",
       "Q 2825 625 2537 362 \n",
       "Q 2250 100 1737 75 \n",
       "Q 1225 50 862 262 \n",
       "Q 500 475 362 862 \n",
       "Q 225 1250 250 1612 \n",
       "z\n",
       "M 1025 787 \n",
       "Q 1250 550 1625 525 \n",
       "Q 2000 500 2250 775 \n",
       "Q 2500 1050 2500 1575 \n",
       "Q 2500 2100 2187 2300 \n",
       "Q 1875 2500 1487 2450 \n",
       "Q 1100 2400 925 2075 \n",
       "Q 750 1750 775 1387 \n",
       "Q 800 1025 1025 787 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-36\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_6\">\n",
       "     <g id=\"line2d_6\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mb81aeef8cd\" x=\"556.230244\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_6\">\n",
       "      <!-- 2020 -->\n",
       "      <g transform=\"translate(546.230244 353.715) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_7\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mb81aeef8cd\" x=\"653.950335\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_7\">\n",
       "      <!-- 2024 -->\n",
       "      <g transform=\"translate(643.950335 353.715) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-34\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_8\">\n",
       "      <defs>\n",
       "       <path id=\"mba1102714c\" d=\"M 0 0 \n",
       "L -3.5 0 \n",
       "\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba1102714c\" x=\"39.2\" y=\"337.016494\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_8\">\n",
       "      <!-- -0.15 -->\n",
       "      <g transform=\"translate(7.2 340.453994) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-2d\" d=\"M 2975 2125 \n",
       "L 125 2125 \n",
       "L 125 2525 \n",
       "L 2975 2525 \n",
       "L 2975 2125 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"SimHei-2e\" d=\"M 1075 125 \n",
       "L 500 125 \n",
       "L 500 675 \n",
       "L 1075 675 \n",
       "L 1075 125 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"SimHei-35\" d=\"M 550 1325 \n",
       "Q 725 650 1150 575 \n",
       "Q 1575 500 1837 662 \n",
       "Q 2100 825 2212 1087 \n",
       "Q 2325 1350 2312 1675 \n",
       "Q 2300 2000 2137 2225 \n",
       "Q 1975 2450 1725 2525 \n",
       "Q 1475 2600 1162 2525 \n",
       "Q 850 2450 650 2175 \n",
       "L 225 2225 \n",
       "Q 275 2375 700 4375 \n",
       "L 2675 4375 \n",
       "L 2675 3925 \n",
       "L 1075 3925 \n",
       "Q 950 3250 825 2850 \n",
       "Q 1200 3025 1525 3012 \n",
       "Q 1850 3000 2150 2862 \n",
       "Q 2450 2725 2587 2487 \n",
       "Q 2725 2250 2787 2012 \n",
       "Q 2850 1775 2837 1500 \n",
       "Q 2825 1225 2725 937 \n",
       "Q 2625 650 2425 462 \n",
       "Q 2225 275 1937 162 \n",
       "Q 1650 50 1275 75 \n",
       "Q 900 100 562 350 \n",
       "Q 225 600 100 1200 \n",
       "L 550 1325 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-2d\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"150\"/>\n",
       "       <use xlink:href=\"#SimHei-35\" x=\"200\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba1102714c\" x=\"39.2\" y=\"285.662126\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_9\">\n",
       "      <!-- -0.10 -->\n",
       "      <g transform=\"translate(7.2 289.099626) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-2d\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"150\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"200\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_10\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba1102714c\" x=\"39.2\" y=\"234.307757\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_10\">\n",
       "      <!-- -0.05 -->\n",
       "      <g transform=\"translate(7.2 237.745257) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-2d\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "       <use xlink:href=\"#SimHei-35\" x=\"200\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba1102714c\" x=\"39.2\" y=\"182.953389\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_11\">\n",
       "      <!-- 0.00 -->\n",
       "      <g transform=\"translate(12.2 186.390889) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-30\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_12\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba1102714c\" x=\"39.2\" y=\"131.599021\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_12\">\n",
       "      <!-- 0.05 -->\n",
       "      <g transform=\"translate(12.2 135.036521) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-30\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-35\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_13\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba1102714c\" x=\"39.2\" y=\"80.244652\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_13\">\n",
       "      <!-- 0.10 -->\n",
       "      <g transform=\"translate(12.2 83.682152) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-30\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_7\">\n",
       "     <g id=\"line2d_14\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba1102714c\" x=\"39.2\" y=\"28.890284\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_14\">\n",
       "      <!-- 0.15 -->\n",
       "      <g transform=\"translate(12.2 32.327784) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-30\"/>\n",
       "       <use xlink:href=\"#SimHei-2e\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-35\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_15\">\n",
       "    <path d=\"M 69.636364 244.971218 \n",
       "L 71.576051 243.8576 \n",
       "L 73.649509 179.104444 \n",
       "L 75.656082 168.105458 \n",
       "L 77.72954 165.306294 \n",
       "L 79.736113 114.606139 \n",
       "L 81.809571 147.974948 \n",
       "L 83.88303 219.509487 \n",
       "L 85.889603 209.018077 \n",
       "L 87.963061 178.515521 \n",
       "L 89.969634 163.357121 \n",
       "L 92.043092 162.754181 \n",
       "L 94.116551 146.315717 \n",
       "L 95.989352 147.261131 \n",
       "L 98.06281 195.108307 \n",
       "L 100.069383 209.375085 \n",
       "L 102.142841 216.810913 \n",
       "L 104.149414 157.410839 \n",
       "L 106.222873 188.783964 \n",
       "L 108.296331 187.801315 \n",
       "L 110.302904 155.071008 \n",
       "L 112.376362 171.436889 \n",
       "L 114.382935 165.762477 \n",
       "L 116.456393 153.650879 \n",
       "L 118.529852 172.179149 \n",
       "L 120.402653 168.063194 \n",
       "L 124.482684 198.232714 \n",
       "L 126.556143 206.234346 \n",
       "L 128.562715 154.341341 \n",
       "L 130.636174 187.511041 \n",
       "L 132.709632 168.489191 \n",
       "L 134.716205 179.618072 \n",
       "L 136.789663 187.988826 \n",
       "L 138.796236 168.213998 \n",
       "L 140.869695 178.499657 \n",
       "L 142.943153 163.551386 \n",
       "L 144.815954 186.396785 \n",
       "L 146.889413 157.296777 \n",
       "L 148.895985 134.590195 \n",
       "L 150.969444 187.553829 \n",
       "L 152.976017 148.647227 \n",
       "L 155.049475 157.165217 \n",
       "L 157.122934 187.272156 \n",
       "L 159.129506 179.39708 \n",
       "L 161.202965 91.092443 \n",
       "L 163.209537 173.906788 \n",
       "L 165.282996 81.802218 \n",
       "L 167.356454 189.925792 \n",
       "L 169.296141 195.819177 \n",
       "L 171.3696 155.205611 \n",
       "L 173.376172 124.568397 \n",
       "L 175.449631 191.517654 \n",
       "L 177.456204 135.038768 \n",
       "L 179.529662 166.163935 \n",
       "L 181.603121 136.499479 \n",
       "L 183.609693 153.332793 \n",
       "L 185.683152 152.228408 \n",
       "L 187.689724 217.59699 \n",
       "L 189.763183 133.541968 \n",
       "L 191.836641 158.996684 \n",
       "L 193.709443 157.648008 \n",
       "L 195.782901 138.604575 \n",
       "L 197.789474 125.720518 \n",
       "L 199.862932 237.688599 \n",
       "L 201.869505 134.507711 \n",
       "L 203.942963 112.722259 \n",
       "L 206.016422 214.574736 \n",
       "L 208.022994 164.963893 \n",
       "L 210.096453 174.769857 \n",
       "L 212.103026 194.584256 \n",
       "L 214.176484 139.484785 \n",
       "L 216.249943 175.315412 \n",
       "L 218.122744 183.42842 \n",
       "L 220.196202 172.804758 \n",
       "L 222.202775 178.772177 \n",
       "L 224.276233 229.966279 \n",
       "L 226.282806 149.599779 \n",
       "L 228.356265 189.730738 \n",
       "L 232.436296 200.234882 \n",
       "L 234.509754 109.708128 \n",
       "L 236.516327 105.678747 \n",
       "L 238.589785 145.639063 \n",
       "L 240.663244 195.020688 \n",
       "L 242.536045 215.710912 \n",
       "L 244.609503 200.446027 \n",
       "L 246.616076 275.957403 \n",
       "L 248.689535 150.868285 \n",
       "L 250.696107 57.404985 \n",
       "L 252.769566 178.03443 \n",
       "L 254.843024 130.922699 \n",
       "L 256.849597 125.50394 \n",
       "L 258.923055 83.066162 \n",
       "L 260.929628 179.373279 \n",
       "L 263.003087 213.196615 \n",
       "L 265.076545 188.860633 \n",
       "L 267.016232 188.667517 \n",
       "L 269.08969 182.369966 \n",
       "L 271.096263 86.846982 \n",
       "L 273.169722 211.013571 \n",
       "L 275.176294 169.026894 \n",
       "L 277.249753 181.051858 \n",
       "L 279.323211 101.516629 \n",
       "L 281.329784 213.096591 \n",
       "L 283.403242 136.421942 \n",
       "L 285.409815 147.816518 \n",
       "L 287.483274 187.596673 \n",
       "L 289.556732 133.008146 \n",
       "L 291.429533 217.563673 \n",
       "L 293.502992 198.614028 \n",
       "L 295.509564 153.668125 \n",
       "L 297.583023 182.636207 \n",
       "L 299.589596 157.644802 \n",
       "L 301.663054 253.564961 \n",
       "L 303.736512 158.240713 \n",
       "L 305.743085 145.022126 \n",
       "L 307.816544 195.960746 \n",
       "L 309.823116 205.152409 \n",
       "L 311.896575 159.610773 \n",
       "L 313.970033 160.999321 \n",
       "L 315.842834 209.875758 \n",
       "L 317.916293 181.625436 \n",
       "L 321.996324 176.374203 \n",
       "L 324.002897 145.985311 \n",
       "L 326.076355 187.079882 \n",
       "L 328.149814 236.857002 \n",
       "L 330.156386 223.541632 \n",
       "L 332.229845 177.703877 \n",
       "L 334.236418 190.222943 \n",
       "L 336.309876 147.768303 \n",
       "L 338.383334 135.45635 \n",
       "L 340.256136 240.970501 \n",
       "L 342.329594 155.136385 \n",
       "L 344.336167 157.149235 \n",
       "L 346.409625 171.272644 \n",
       "L 348.416198 182.283906 \n",
       "L 350.489656 201.914014 \n",
       "L 354.569688 139.978306 \n",
       "L 356.643146 171.048894 \n",
       "L 358.649719 194.686395 \n",
       "L 360.723177 80.501507 \n",
       "L 362.796636 143.391409 \n",
       "L 364.736323 212.389455 \n",
       "L 366.809781 165.582086 \n",
       "L 368.816354 175.831175 \n",
       "L 370.889812 193.174145 \n",
       "L 372.896385 148.312277 \n",
       "L 374.969843 147.566419 \n",
       "L 377.043302 191.318075 \n",
       "L 379.049875 180.62822 \n",
       "L 381.123333 176.206296 \n",
       "L 383.129906 129.644076 \n",
       "L 385.203364 184.212451 \n",
       "L 387.276823 187.713455 \n",
       "L 389.149624 196.065563 \n",
       "L 391.223082 192.331668 \n",
       "L 393.229655 166.957825 \n",
       "L 395.303114 225.748017 \n",
       "L 397.309686 150.739453 \n",
       "L 399.383145 213.899151 \n",
       "L 401.456603 177.643909 \n",
       "L 403.463176 210.008859 \n",
       "L 405.536634 128.176003 \n",
       "L 407.543207 212.26259 \n",
       "L 409.616666 145.062073 \n",
       "L 411.690124 248.416915 \n",
       "L 413.562925 192.810965 \n",
       "L 415.636384 124.965972 \n",
       "L 417.642956 162.533263 \n",
       "L 419.716415 215.060286 \n",
       "L 421.722987 204.710569 \n",
       "L 423.796446 150.228053 \n",
       "L 425.869904 216.747715 \n",
       "L 427.876477 213.89693 \n",
       "L 429.949936 157.13122 \n",
       "L 431.956508 132.313565 \n",
       "L 434.029967 22.32 \n",
       "L 436.103425 219.896234 \n",
       "L 437.976226 223.828481 \n",
       "L 440.049685 246.811733 \n",
       "L 442.056258 196.795345 \n",
       "L 444.129716 286.23051 \n",
       "L 446.136289 98.535364 \n",
       "L 448.209747 99.705698 \n",
       "L 450.283206 143.163236 \n",
       "L 452.289778 161.430011 \n",
       "L 454.363237 260.952168 \n",
       "L 456.36981 185.352716 \n",
       "L 458.443268 156.679874 \n",
       "L 460.516726 114.288351 \n",
       "L 462.456413 177.325644 \n",
       "L 464.529872 192.065116 \n",
       "L 466.536445 169.741476 \n",
       "L 468.609903 162.953508 \n",
       "L 470.616476 187.690959 \n",
       "L 472.689934 128.774098 \n",
       "L 474.763393 185.404325 \n",
       "L 476.769965 167.575673 \n",
       "L 478.843424 191.634682 \n",
       "L 480.849997 175.177974 \n",
       "L 482.923455 181.799715 \n",
       "L 484.996913 164.934397 \n",
       "L 486.869715 180.296795 \n",
       "L 488.943173 149.203193 \n",
       "L 490.949746 125.231307 \n",
       "L 493.023204 131.387609 \n",
       "L 495.029777 161.382774 \n",
       "L 497.103235 154.740006 \n",
       "L 499.176694 198.168814 \n",
       "L 501.183267 196.65966 \n",
       "L 503.256725 140.884742 \n",
       "L 505.263298 155.063206 \n",
       "L 507.336756 163.401149 \n",
       "L 509.410215 94.827029 \n",
       "L 511.283016 195.762921 \n",
       "L 513.356474 257.219415 \n",
       "L 515.363047 188.452591 \n",
       "L 517.436505 156.999787 \n",
       "L 519.443078 149.45131 \n",
       "L 521.516537 148.629899 \n",
       "L 523.589995 173.7052 \n",
       "L 525.596568 157.329292 \n",
       "L 527.670026 148.051773 \n",
       "L 529.676599 214.665938 \n",
       "L 531.750057 172.316729 \n",
       "L 533.823516 136.188088 \n",
       "L 535.696317 280.961572 \n",
       "L 537.769776 224.422878 \n",
       "L 539.776348 145.955707 \n",
       "L 541.849807 183.517161 \n",
       "L 543.856379 147.718627 \n",
       "L 545.929838 173.055986 \n",
       "L 548.003296 226.701038 \n",
       "L 550.009869 165.171592 \n",
       "L 552.083328 174.843401 \n",
       "L 554.0899 170.842058 \n",
       "L 556.163359 186.821473 \n",
       "L 558.236817 231.151308 \n",
       "L 560.176504 244.019964 \n",
       "L 562.249963 116.376553 \n",
       "L 564.256535 189.741658 \n",
       "L 566.329994 195.935965 \n",
       "L 568.336566 215.437433 \n",
       "L 570.410025 192.515625 \n",
       "L 572.483483 145.694747 \n",
       "L 574.490056 174.637811 \n",
       "L 576.563514 183.878404 \n",
       "L 578.570087 143.791201 \n",
       "L 580.643546 227.147235 \n",
       "L 582.717004 164.053308 \n",
       "L 584.589805 123.422039 \n",
       "L 586.663264 137.827059 \n",
       "L 588.669836 251.633967 \n",
       "L 590.743295 227.696393 \n",
       "L 592.749868 238.376942 \n",
       "L 594.823326 231.887074 \n",
       "L 596.896785 137.280498 \n",
       "L 598.903357 124.881448 \n",
       "L 600.976816 227.718254 \n",
       "L 602.983388 221.975364 \n",
       "L 605.056847 124.461893 \n",
       "L 607.130305 121.388431 \n",
       "L 609.003107 175.314807 \n",
       "L 611.076565 144.233596 \n",
       "L 613.083138 110.332238 \n",
       "L 615.156596 218.996712 \n",
       "L 617.163169 208.230935 \n",
       "L 619.236627 202.360416 \n",
       "L 621.310086 149.08695 \n",
       "L 623.316659 152.991287 \n",
       "L 625.390117 228.050234 \n",
       "L 627.39669 150.605094 \n",
       "L 629.470148 180.020124 \n",
       "L 631.543607 167.564376 \n",
       "L 633.416408 178.076948 \n",
       "L 635.489866 196.47271 \n",
       "L 637.496439 133.055489 \n",
       "L 639.569897 189.311196 \n",
       "L 641.57647 163.264629 \n",
       "L 643.649929 152.221215 \n",
       "L 645.723387 174.964361 \n",
       "L 647.72996 171.268573 \n",
       "L 649.803418 217.906627 \n",
       "L 651.809991 196.423354 \n",
       "L 653.883449 160.463994 \n",
       "L 655.956908 59.240809 \n",
       "L 657.896595 197.944451 \n",
       "L 659.970053 166.619914 \n",
       "L 661.976626 121.88472 \n",
       "L 664.050084 147.411637 \n",
       "L 666.056657 144.914236 \n",
       "L 668.130116 212.164412 \n",
       "L 670.203574 163.574582 \n",
       "L 672.210147 257.19839 \n",
       "L 674.283605 324.72 \n",
       "L 676.290178 163.79397 \n",
       "L 678.363636 95.281645 \n",
       "L 678.363636 95.281645 \n",
       "\" clip-path=\"url(#p35c216fe3f)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 39.2 339.84 \n",
       "L 39.2 7.2 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 708.8 339.84 \n",
       "L 708.8 7.2 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 39.2 339.84 \n",
       "L 708.8 339.84 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path d=\"M 39.2 7.2 \n",
       "L 708.8 7.2 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"legend_1\">\n",
       "    <g id=\"patch_7\">\n",
       "     <path d=\"M 46.2 28.45 \n",
       "L 93.2 28.45 \n",
       "Q 95.2 28.45 95.2 26.45 \n",
       "L 95.2 14.2 \n",
       "Q 95.2 12.2 93.2 12.2 \n",
       "L 46.2 12.2 \n",
       "Q 44.2 12.2 44.2 14.2 \n",
       "L 44.2 26.45 \n",
       "Q 44.2 28.45 46.2 28.45 \n",
       "z\n",
       "\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n",
       "    </g>\n",
       "    <g id=\"line2d_16\">\n",
       "     <path d=\"M 48.2 19.7 \n",
       "L 58.2 19.7 \n",
       "L 68.2 19.7 \n",
       "\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "    </g>\n",
       "    <g id=\"text_15\">\n",
       "     <!-- HML -->\n",
       "     <g transform=\"translate(76.2 23.2) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"SimHei-48\" d=\"M 2850 125 \n",
       "L 2275 125 \n",
       "L 2275 2125 \n",
       "L 850 2125 \n",
       "L 850 125 \n",
       "L 275 125 \n",
       "L 275 4400 \n",
       "L 850 4400 \n",
       "L 850 2600 \n",
       "L 2275 2600 \n",
       "L 2275 4400 \n",
       "L 2850 4400 \n",
       "L 2850 125 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"SimHei-4d\" d=\"M 2925 125 \n",
       "L 2425 125 \n",
       "L 2425 3175 \n",
       "L 2375 3175 \n",
       "L 1775 125 \n",
       "L 1375 125 \n",
       "L 775 3175 \n",
       "L 725 3175 \n",
       "L 725 125 \n",
       "L 225 125 \n",
       "L 225 4400 \n",
       "L 1000 4400 \n",
       "L 1550 1575 \n",
       "L 1600 1575 \n",
       "L 2150 4400 \n",
       "L 2925 4400 \n",
       "L 2925 125 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"SimHei-4c\" d=\"M 2900 125 \n",
       "L 300 125 \n",
       "L 300 4400 \n",
       "L 875 4400 \n",
       "L 875 600 \n",
       "L 2900 600 \n",
       "L 2900 125 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#SimHei-48\"/>\n",
       "      <use xlink:href=\"#SimHei-4d\" x=\"50\"/>\n",
       "      <use xlink:href=\"#SimHei-4c\" x=\"100\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p35c216fe3f\">\n",
       "   <rect x=\"39.2\" y=\"7.2\" width=\"669.6\" height=\"332.64\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<Figure size 1200x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot HML\n",
    "fig = plt.figure(figsize=(12,6))\n",
    "plt.plot(factors['HML'], label='HML')\n",
    "plt.legend(loc='upper left')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f9c7ff1f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MKT</th>\n",
       "      <th>SMB</th>\n",
       "      <th>HML</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>203.000000</td>\n",
       "      <td>203.000000</td>\n",
       "      <td>203.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.008284</td>\n",
       "      <td>0.009550</td>\n",
       "      <td>0.010069</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.085793</td>\n",
       "      <td>0.043900</td>\n",
       "      <td>0.037419</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-0.268349</td>\n",
       "      <td>-0.182035</td>\n",
       "      <td>-0.100553</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>-0.049183</td>\n",
       "      <td>-0.013224</td>\n",
       "      <td>-0.011374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.011574</td>\n",
       "      <td>0.007845</td>\n",
       "      <td>0.007437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.050141</td>\n",
       "      <td>0.030612</td>\n",
       "      <td>0.031613</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>0.296042</td>\n",
       "      <td>0.158098</td>\n",
       "      <td>0.156397</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              MKT         SMB         HML\n",
       "count  203.000000  203.000000  203.000000\n",
       "mean     0.008284    0.009550    0.010069\n",
       "std      0.085793    0.043900    0.037419\n",
       "min     -0.268349   -0.182035   -0.100553\n",
       "25%     -0.049183   -0.013224   -0.011374\n",
       "50%      0.011574    0.007845    0.007437\n",
       "75%      0.050141    0.030612    0.031613\n",
       "max      0.296042    0.158098    0.156397"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MKT</th>\n",
       "      <th>SMB</th>\n",
       "      <th>HML</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>MKT</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.218870</td>\n",
       "      <td>-0.319177</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SMB</th>\n",
       "      <td>0.218870</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.600943</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>HML</th>\n",
       "      <td>-0.319177</td>\n",
       "      <td>-0.600943</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          MKT       SMB       HML\n",
       "MKT  1.000000  0.218870 -0.319177\n",
       "SMB  0.218870  1.000000 -0.600943\n",
       "HML -0.319177 -0.600943  1.000000"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# summary of the factor\n",
    "factors[:'2020-12'].describe()\n",
    "factors[:'2020-12'].corr()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cd3185b4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:                    SMB   R-squared:                      -0.000\n",
      "Model:                            OLS   Adj. R-squared:                 -0.000\n",
      "Method:                 Least Squares   F-statistic:                       nan\n",
      "Date:                Mon, 01 Dec 2025   Prob (F-statistic):                nan\n",
      "Time:                        20:37:59   Log-Likelihood:                 523.12\n",
      "No. Observations:                 299   AIC:                            -1044.\n",
      "Df Residuals:                     298   BIC:                            -1041.\n",
      "Df Model:                           0                                         \n",
      "Covariance Type:                  HAC                                         \n",
      "==============================================================================\n",
      "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      0.0061      0.003      2.391      0.017       0.001       0.011\n",
      "==============================================================================\n",
      "Omnibus:                       15.034   Durbin-Watson:                   1.840\n",
      "Prob(Omnibus):                  0.001   Jarque-Bera (JB):               38.692\n",
      "Skew:                          -0.005   Prob(JB):                     3.96e-09\n",
      "Kurtosis:                       4.762   Cond. No.                         1.00\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 2 lags and without small sample correction\n"
     ]
    }
   ],
   "source": [
    "# regression\n",
    "model = smf.ols('SMB ~ 1',\n",
    "                 data=factors['2010-01':'2024-12']).fit(\n",
    "                     cov_type='HAC', cov_kwds={'maxlags': 2})\n",
    "print(model.summary())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c249a7e7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# regression\n",
    "model = smf.ols('HML ~ 1',\n",
    "                 data=factors['2010-01':'2024-12']).fit(\n",
    "                     cov_type='HAC', cov_kwds={'maxlags': 2})\n",
    "print(model.summary())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "20b18aba",
   "metadata": {},
   "source": [
    "价钱的图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "ffa2d095",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x1e37a5d1870>]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x1e37a611ae0>]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1e37a5d24d0>"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "([<matplotlib.axis.XTick at 0x1e37a5d1690>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a5d0fd0>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a612c80>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a6448b0>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a644f70>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a645a20>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a6464d0>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a646f80>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a613640>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a6455d0>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a658400>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a658eb0>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a659960>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a647610>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a65a260>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a65ad10>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a65b7c0>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a67c2b0>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a65a860>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a67ccd0>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a67d780>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a67e230>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a67ece0>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a67dbd0>,\n",
       "  <matplotlib.axis.XTick at 0x1e37a67f610>],\n",
       " [Text(10987.0, 0, '2000'),\n",
       "  Text(11353.0, 0, '2001'),\n",
       "  Text(11718.0, 0, '2002'),\n",
       "  Text(12111.0, 0, '2003'),\n",
       "  Text(12477.0, 0, '2004'),\n",
       "  Text(12842.0, 0, '2005'),\n",
       "  Text(13207.0, 0, '2006'),\n",
       "  Text(13572.0, 0, '2007'),\n",
       "  Text(13938.0, 0, '2008'),\n",
       "  Text(14303.0, 0, '2009'),\n",
       "  Text(14668.0, 0, '2010'),\n",
       "  Text(15033.0, 0, '2011'),\n",
       "  Text(15399.0, 0, '2012'),\n",
       "  Text(15764.0, 0, '2013'),\n",
       "  Text(16129.0, 0, '2014'),\n",
       "  Text(16494.0, 0, '2015'),\n",
       "  Text(16860.0, 0, '2016'),\n",
       "  Text(17225.0, 0, '2017'),\n",
       "  Text(17590.0, 0, '2018'),\n",
       "  Text(17955.0, 0, '2019'),\n",
       "  Text(18321.0, 0, '2020'),\n",
       "  Text(18686.0, 0, '2021'),\n",
       "  Text(19051.0, 0, '2022'),\n",
       "  Text(19416.0, 0, '2023'),\n",
       "  Text(19782.0, 0, '2024')])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"701pt\" height=\"374.04pt\" viewBox=\"0 0 701 374.04\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:date>2025-12-01T20:41:39.097915</dc:date>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Matplotlib v3.7.0, https://matplotlib.org/</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 374.04 \n",
       "L 701 374.04 \n",
       "L 701 0 \n",
       "L 0 0 \n",
       "z\n",
       "\" style=\"fill: #ffffff\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 24.2 339.84 \n",
       "L 693.8 339.84 \n",
       "L 693.8 7.2 \n",
       "L 24.2 7.2 \n",
       "z\n",
       "\" style=\"fill: #ffffff\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <defs>\n",
       "       <path id=\"m2e7b1fa44a\" d=\"M 0 0 \n",
       "L 0 3.5 \n",
       "\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"54.636364\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_1\">\n",
       "      <!-- 2000 -->\n",
       "      <g transform=\"translate(57.448864 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-32\" d=\"M 300 250 \n",
       "Q 325 625 650 925 \n",
       "Q 975 1225 1475 1862 \n",
       "Q 1975 2500 2125 2850 \n",
       "Q 2275 3200 2237 3450 \n",
       "Q 2200 3700 2000 3862 \n",
       "Q 1800 4025 1537 4000 \n",
       "Q 1275 3975 1037 3800 \n",
       "Q 800 3625 675 3275 \n",
       "L 200 3350 \n",
       "Q 400 3925 712 4187 \n",
       "Q 1025 4450 1450 4475 \n",
       "Q 1700 4500 1900 4462 \n",
       "Q 2100 4425 2312 4287 \n",
       "Q 2525 4150 2662 3875 \n",
       "Q 2800 3600 2762 3212 \n",
       "Q 2725 2825 2375 2287 \n",
       "Q 2025 1750 1025 600 \n",
       "L 2825 600 \n",
       "L 2825 150 \n",
       "L 300 150 \n",
       "L 300 250 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"SimHei-30\" d=\"M 225 2537 \n",
       "Q 250 3200 412 3587 \n",
       "Q 575 3975 875 4225 \n",
       "Q 1175 4475 1612 4475 \n",
       "Q 2050 4475 2375 4112 \n",
       "Q 2700 3750 2800 3200 \n",
       "Q 2900 2650 2862 1937 \n",
       "Q 2825 1225 2612 775 \n",
       "Q 2400 325 1975 150 \n",
       "Q 1550 -25 1125 187 \n",
       "Q 700 400 525 750 \n",
       "Q 350 1100 275 1487 \n",
       "Q 200 1875 225 2537 \n",
       "z\n",
       "M 750 2687 \n",
       "Q 675 2000 800 1462 \n",
       "Q 925 925 1212 700 \n",
       "Q 1500 475 1800 612 \n",
       "Q 2100 750 2237 1162 \n",
       "Q 2375 1575 2375 2062 \n",
       "Q 2375 2550 2337 2950 \n",
       "Q 2300 3350 2112 3675 \n",
       "Q 1925 4000 1612 4012 \n",
       "Q 1300 4025 1062 3700 \n",
       "Q 825 3375 750 2687 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_2\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"79.116551\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_2\">\n",
       "      <!-- 2001 -->\n",
       "      <g transform=\"translate(81.929051 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-31\" d=\"M 1400 3600 \n",
       "Q 1075 3275 575 2975 \n",
       "L 575 3450 \n",
       "Q 1200 3875 1600 4450 \n",
       "L 1900 4450 \n",
       "L 1900 150 \n",
       "L 1400 150 \n",
       "L 1400 3600 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"103.529852\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_3\">\n",
       "      <!-- 2002 -->\n",
       "      <g transform=\"translate(106.342352 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_4\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"129.815954\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_4\">\n",
       "      <!-- 2003 -->\n",
       "      <g transform=\"translate(132.628454 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-33\" d=\"M 250 1225 \n",
       "L 700 1300 \n",
       "Q 800 975 1025 762 \n",
       "Q 1250 550 1587 562 \n",
       "Q 1925 575 2125 837 \n",
       "Q 2325 1100 2300 1437 \n",
       "Q 2275 1775 2037 1962 \n",
       "Q 1800 2150 1275 2225 \n",
       "L 1275 2550 \n",
       "Q 1800 2600 2037 2825 \n",
       "Q 2275 3050 2250 3412 \n",
       "Q 2225 3775 1925 3937 \n",
       "Q 1625 4100 1287 3975 \n",
       "Q 950 3850 750 3275 \n",
       "L 300 3350 \n",
       "Q 450 3800 712 4100 \n",
       "Q 975 4400 1425 4450 \n",
       "Q 1875 4500 2212 4337 \n",
       "Q 2550 4175 2687 3837 \n",
       "Q 2825 3500 2725 3100 \n",
       "Q 2625 2700 2150 2400 \n",
       "Q 2500 2250 2687 1950 \n",
       "Q 2875 1650 2812 1162 \n",
       "Q 2750 675 2375 375 \n",
       "Q 2000 75 1525 87 \n",
       "Q 1050 100 700 387 \n",
       "Q 350 675 250 1225 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-33\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"154.296141\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_5\">\n",
       "      <!-- 2004 -->\n",
       "      <g transform=\"translate(157.108641 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-34\" d=\"M 2000 1100 \n",
       "L 75 1100 \n",
       "L 75 1525 \n",
       "L 2100 4450 \n",
       "L 2475 4450 \n",
       "L 2475 1525 \n",
       "L 3075 1525 \n",
       "L 3075 1100 \n",
       "L 2475 1100 \n",
       "L 2475 150 \n",
       "L 2000 150 \n",
       "L 2000 1100 \n",
       "z\n",
       "M 2000 1525 \n",
       "L 2000 3500 \n",
       "L 600 1525 \n",
       "L 2000 1525 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-34\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_6\">\n",
       "     <g id=\"line2d_6\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"178.709443\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_6\">\n",
       "      <!-- 2005 -->\n",
       "      <g transform=\"translate(181.521943 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-35\" d=\"M 550 1325 \n",
       "Q 725 650 1150 575 \n",
       "Q 1575 500 1837 662 \n",
       "Q 2100 825 2212 1087 \n",
       "Q 2325 1350 2312 1675 \n",
       "Q 2300 2000 2137 2225 \n",
       "Q 1975 2450 1725 2525 \n",
       "Q 1475 2600 1162 2525 \n",
       "Q 850 2450 650 2175 \n",
       "L 225 2225 \n",
       "Q 275 2375 700 4375 \n",
       "L 2675 4375 \n",
       "L 2675 3925 \n",
       "L 1075 3925 \n",
       "Q 950 3250 825 2850 \n",
       "Q 1200 3025 1525 3012 \n",
       "Q 1850 3000 2150 2862 \n",
       "Q 2450 2725 2587 2487 \n",
       "Q 2725 2250 2787 2012 \n",
       "Q 2850 1775 2837 1500 \n",
       "Q 2825 1225 2725 937 \n",
       "Q 2625 650 2425 462 \n",
       "Q 2225 275 1937 162 \n",
       "Q 1650 50 1275 75 \n",
       "Q 900 100 562 350 \n",
       "Q 225 600 100 1200 \n",
       "L 550 1325 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-35\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_7\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"203.122744\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_7\">\n",
       "      <!-- 2006 -->\n",
       "      <g transform=\"translate(205.935244 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-36\" d=\"M 250 1612 \n",
       "Q 275 1975 387 2225 \n",
       "Q 500 2475 725 2850 \n",
       "L 1750 4450 \n",
       "L 2325 4450 \n",
       "L 1275 2800 \n",
       "Q 1950 2975 2350 2750 \n",
       "Q 2750 2525 2887 2237 \n",
       "Q 3025 1950 3037 1612 \n",
       "Q 3050 1275 2937 950 \n",
       "Q 2825 625 2537 362 \n",
       "Q 2250 100 1737 75 \n",
       "Q 1225 50 862 262 \n",
       "Q 500 475 362 862 \n",
       "Q 225 1250 250 1612 \n",
       "z\n",
       "M 1025 787 \n",
       "Q 1250 550 1625 525 \n",
       "Q 2000 500 2250 775 \n",
       "Q 2500 1050 2500 1575 \n",
       "Q 2500 2100 2187 2300 \n",
       "Q 1875 2500 1487 2450 \n",
       "Q 1100 2400 925 2075 \n",
       "Q 750 1750 775 1387 \n",
       "Q 800 1025 1025 787 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-36\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_8\">\n",
       "     <g id=\"line2d_8\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"227.536045\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_8\">\n",
       "      <!-- 2007 -->\n",
       "      <g transform=\"translate(230.348545 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-37\" d=\"M 850 150 \n",
       "Q 1300 2050 2425 3925 \n",
       "L 275 3925 \n",
       "L 275 4375 \n",
       "L 2950 4375 \n",
       "L 2950 3950 \n",
       "Q 1775 2050 1400 150 \n",
       "L 850 150 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-37\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_9\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"252.016232\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_9\">\n",
       "      <!-- 2008 -->\n",
       "      <g transform=\"translate(254.828732 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-38\" d=\"M 175 1375 \n",
       "Q 175 1675 325 1962 \n",
       "Q 475 2250 825 2425 \n",
       "Q 525 2600 425 2812 \n",
       "Q 325 3025 312 3300 \n",
       "Q 300 3575 387 3775 \n",
       "Q 475 3975 650 4150 \n",
       "Q 825 4325 1037 4387 \n",
       "Q 1250 4450 1500 4450 \n",
       "Q 1750 4450 1950 4400 \n",
       "Q 2150 4350 2375 4187 \n",
       "Q 2600 4025 2700 3725 \n",
       "Q 2800 3425 2687 3025 \n",
       "Q 2575 2625 2100 2400 \n",
       "Q 2525 2275 2700 2012 \n",
       "Q 2875 1750 2875 1375 \n",
       "Q 2875 1000 2762 775 \n",
       "Q 2650 550 2512 400 \n",
       "Q 2375 250 2137 162 \n",
       "Q 1900 75 1537 75 \n",
       "Q 1175 75 912 162 \n",
       "Q 650 250 475 425 \n",
       "Q 300 600 237 837 \n",
       "Q 175 1075 175 1375 \n",
       "z\n",
       "M 687 1400 \n",
       "Q 675 1100 787 875 \n",
       "Q 900 650 1200 587 \n",
       "Q 1500 525 1825 600 \n",
       "Q 2150 675 2275 950 \n",
       "Q 2400 1225 2362 1500 \n",
       "Q 2325 1775 2050 1962 \n",
       "Q 1775 2150 1450 2125 \n",
       "Q 1125 2100 912 1900 \n",
       "Q 700 1700 687 1400 \n",
       "z\n",
       "M 775 3350 \n",
       "Q 775 3100 950 2875 \n",
       "Q 1125 2650 1500 2650 \n",
       "Q 1875 2650 2062 2875 \n",
       "Q 2250 3100 2237 3412 \n",
       "Q 2225 3725 2012 3875 \n",
       "Q 1800 4025 1437 4000 \n",
       "Q 1075 3975 925 3787 \n",
       "Q 775 3600 775 3350 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-38\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_10\">\n",
       "     <g id=\"line2d_10\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"276.429533\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_10\">\n",
       "      <!-- 2009 -->\n",
       "      <g transform=\"translate(279.242033 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"SimHei-39\" d=\"M 800 75 \n",
       "Q 1350 1000 1700 1750 \n",
       "Q 1075 1650 662 1912 \n",
       "Q 250 2175 162 2625 \n",
       "Q 75 3075 175 3437 \n",
       "Q 275 3800 487 4037 \n",
       "Q 700 4275 1000 4375 \n",
       "Q 1300 4475 1537 4475 \n",
       "Q 1775 4475 2025 4375 \n",
       "Q 2275 4275 2475 4075 \n",
       "Q 2675 3875 2750 3662 \n",
       "Q 2825 3450 2825 3112 \n",
       "Q 2825 2775 2575 2250 \n",
       "Q 2325 1725 1350 75 \n",
       "L 800 75 \n",
       "z\n",
       "M 662 2875 \n",
       "Q 700 2550 937 2337 \n",
       "Q 1175 2125 1450 2150 \n",
       "Q 1725 2175 1887 2300 \n",
       "Q 2050 2425 2200 2725 \n",
       "Q 2300 3100 2250 3362 \n",
       "Q 2200 3625 1987 3800 \n",
       "Q 1775 3975 1525 3975 \n",
       "Q 1375 4000 1137 3900 \n",
       "Q 900 3800 762 3500 \n",
       "Q 625 3200 662 2875 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-39\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_11\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"300.842834\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_11\">\n",
       "      <!-- 2010 -->\n",
       "      <g transform=\"translate(303.655334 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_12\">\n",
       "     <g id=\"line2d_12\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"325.256136\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_12\">\n",
       "      <!-- 2011 -->\n",
       "      <g transform=\"translate(328.068636 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_13\">\n",
       "     <g id=\"line2d_13\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"349.736323\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_13\">\n",
       "      <!-- 2012 -->\n",
       "      <g transform=\"translate(352.548823 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_14\">\n",
       "     <g id=\"line2d_14\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"374.149624\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_14\">\n",
       "      <!-- 2013 -->\n",
       "      <g transform=\"translate(376.962124 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-33\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_15\">\n",
       "     <g id=\"line2d_15\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"398.562925\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_15\">\n",
       "      <!-- 2014 -->\n",
       "      <g transform=\"translate(401.375425 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-34\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_16\">\n",
       "     <g id=\"line2d_16\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"422.976226\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_16\">\n",
       "      <!-- 2015 -->\n",
       "      <g transform=\"translate(425.788726 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-35\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_17\">\n",
       "     <g id=\"line2d_17\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"447.456413\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_17\">\n",
       "      <!-- 2016 -->\n",
       "      <g transform=\"translate(450.268913 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-36\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_18\">\n",
       "     <g id=\"line2d_18\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"471.869715\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_18\">\n",
       "      <!-- 2017 -->\n",
       "      <g transform=\"translate(474.682215 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-37\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_19\">\n",
       "     <g id=\"line2d_19\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"496.283016\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_19\">\n",
       "      <!-- 2018 -->\n",
       "      <g transform=\"translate(499.095516 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-38\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_20\">\n",
       "     <g id=\"line2d_20\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"520.696317\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_20\">\n",
       "      <!-- 2019 -->\n",
       "      <g transform=\"translate(523.508817 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-39\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_21\">\n",
       "     <g id=\"line2d_21\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"545.176504\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_21\">\n",
       "      <!-- 2020 -->\n",
       "      <g transform=\"translate(547.989004 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_22\">\n",
       "     <g id=\"line2d_22\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"569.589805\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_22\">\n",
       "      <!-- 2021 -->\n",
       "      <g transform=\"translate(572.402305 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-31\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_23\">\n",
       "     <g id=\"line2d_23\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"594.003107\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_23\">\n",
       "      <!-- 2022 -->\n",
       "      <g transform=\"translate(596.815607 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_24\">\n",
       "     <g id=\"line2d_24\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"618.416408\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_24\">\n",
       "      <!-- 2023 -->\n",
       "      <g transform=\"translate(621.228908 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-33\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_25\">\n",
       "     <g id=\"line2d_25\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m2e7b1fa44a\" x=\"642.896595\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_25\">\n",
       "      <!-- 2024 -->\n",
       "      <g transform=\"translate(645.709095 366.84) rotate(-90) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"100\"/>\n",
       "       <use xlink:href=\"#SimHei-34\" x=\"150\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_26\">\n",
       "      <defs>\n",
       "       <path id=\"mbf47d3c061\" d=\"M 0 0 \n",
       "L -3.5 0 \n",
       "\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#mbf47d3c061\" x=\"24.2\" y=\"298.607159\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_26\">\n",
       "      <!-- 2 -->\n",
       "      <g transform=\"translate(12.2 302.044659) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-32\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_27\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mbf47d3c061\" x=\"24.2\" y=\"251.814131\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_27\">\n",
       "      <!-- 4 -->\n",
       "      <g transform=\"translate(12.2 255.251631) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-34\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_28\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mbf47d3c061\" x=\"24.2\" y=\"205.021103\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_28\">\n",
       "      <!-- 6 -->\n",
       "      <g transform=\"translate(12.2 208.458603) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-36\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_29\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mbf47d3c061\" x=\"24.2\" y=\"158.228075\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_29\">\n",
       "      <!-- 8 -->\n",
       "      <g transform=\"translate(12.2 161.665575) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-38\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_30\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mbf47d3c061\" x=\"24.2\" y=\"111.435048\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_30\">\n",
       "      <!-- 10 -->\n",
       "      <g transform=\"translate(7.2 114.872548) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-31\"/>\n",
       "       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_31\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mbf47d3c061\" x=\"24.2\" y=\"64.64202\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_31\">\n",
       "      <!-- 12 -->\n",
       "      <g transform=\"translate(7.2 68.07952) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-31\"/>\n",
       "       <use xlink:href=\"#SimHei-32\" x=\"50\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_7\">\n",
       "     <g id=\"line2d_32\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mbf47d3c061\" x=\"24.2\" y=\"17.848992\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_32\">\n",
       "      <!-- 14 -->\n",
       "      <g transform=\"translate(7.2 21.286492) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#SimHei-31\"/>\n",
       "       <use xlink:href=\"#SimHei-34\" x=\"50\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_33\">\n",
       "    <path d=\"M 54.636364 322.342806 \n",
       "L 56.576051 321.738647 \n",
       "L 58.649509 319.780359 \n",
       "L 60.656082 319.782934 \n",
       "L 62.72954 319.174624 \n",
       "L 64.736113 318.923301 \n",
       "L 66.809571 318.550056 \n",
       "L 68.88303 317.979815 \n",
       "L 70.889603 317.586473 \n",
       "L 72.963061 316.769649 \n",
       "L 74.969634 316.418539 \n",
       "L 77.043092 315.853058 \n",
       "L 79.116551 315.701152 \n",
       "L 80.989352 315.919982 \n",
       "L 83.06281 315.530016 \n",
       "L 85.069383 315.280522 \n",
       "L 87.142841 314.408673 \n",
       "L 89.149414 313.876276 \n",
       "L 91.222873 314.030743 \n",
       "L 93.296331 313.789686 \n",
       "L 97.376362 314.526727 \n",
       "L 99.382935 313.806744 \n",
       "L 101.456393 314.249888 \n",
       "L 103.529852 315.518407 \n",
       "L 105.402653 314.807665 \n",
       "L 109.482684 314.354718 \n",
       "L 111.556143 314.769414 \n",
       "L 113.562715 315.567345 \n",
       "L 115.636174 315.177955 \n",
       "L 117.709632 315.20135 \n",
       "L 121.789663 315.745985 \n",
       "L 123.796236 316.786526 \n",
       "L 125.869695 316.932705 \n",
       "L 127.943153 316.422317 \n",
       "L 129.815954 316.194973 \n",
       "L 131.889413 317.18549 \n",
       "L 133.895985 318.826614 \n",
       "L 135.969444 319.075232 \n",
       "L 137.976017 319.153618 \n",
       "L 140.049475 320.018773 \n",
       "L 142.122934 319.688495 \n",
       "L 144.129506 319.646778 \n",
       "L 146.202965 320.703563 \n",
       "L 148.209537 320.516009 \n",
       "L 150.282996 322.121334 \n",
       "L 154.296141 320.147559 \n",
       "L 158.376172 319.345846 \n",
       "L 160.449631 319.144052 \n",
       "L 164.529662 320.24574 \n",
       "L 168.609693 320.085324 \n",
       "L 170.683152 320.282783 \n",
       "L 172.689724 319.387939 \n",
       "L 176.836641 319.849748 \n",
       "L 178.709443 319.402272 \n",
       "L 180.782901 320.219246 \n",
       "L 182.789474 321.556486 \n",
       "L 184.862932 320.32477 \n",
       "L 186.869505 320.803565 \n",
       "L 188.942963 322.510975 \n",
       "L 191.016422 320.685766 \n",
       "L 193.022994 319.950441 \n",
       "L 195.096453 320.246266 \n",
       "L 197.103026 319.949845 \n",
       "L 199.176484 321.068549 \n",
       "L 203.122744 321.286883 \n",
       "L 205.196202 321.497405 \n",
       "L 207.202775 322.432664 \n",
       "L 209.276233 319.775346 \n",
       "L 213.356265 317.563919 \n",
       "L 215.429723 317.852205 \n",
       "L 219.509754 318.782888 \n",
       "L 221.516327 321.59296 \n",
       "L 223.589785 324.060591 \n",
       "L 225.663244 322.350055 \n",
       "L 227.536045 319.465603 \n",
       "L 229.609503 317.458297 \n",
       "L 231.616076 315.843532 \n",
       "L 233.689535 316.76496 \n",
       "L 235.696107 318.579169 \n",
       "L 237.769566 316.785828 \n",
       "L 239.843024 317.892658 \n",
       "L 241.849597 318.154426 \n",
       "L 243.923055 321.012455 \n",
       "L 245.929628 318.461614 \n",
       "L 248.003087 316.796127 \n",
       "L 250.076545 314.695646 \n",
       "L 252.016232 312.110253 \n",
       "L 254.08969 311.90456 \n",
       "L 256.096263 314.227728 \n",
       "L 258.169722 312.92346 \n",
       "L 260.176294 314.53367 \n",
       "L 262.249753 312.239667 \n",
       "L 264.323211 313.950886 \n",
       "L 266.329784 315.383476 \n",
       "L 268.403242 315.148975 \n",
       "L 270.409815 311.063401 \n",
       "L 272.483274 309.013814 \n",
       "L 274.556732 306.036483 \n",
       "L 276.429533 304.86078 \n",
       "L 278.502992 302.53838 \n",
       "L 280.509564 301.311085 \n",
       "L 282.583023 300.413339 \n",
       "L 284.589596 303.971106 \n",
       "L 286.663054 306.132724 \n",
       "L 288.736512 302.801672 \n",
       "L 290.743085 303.127423 \n",
       "L 292.816544 301.402252 \n",
       "L 294.823116 297.577454 \n",
       "L 296.896575 296.593482 \n",
       "L 298.970033 292.578604 \n",
       "L 300.842834 290.875499 \n",
       "L 302.916293 289.687784 \n",
       "L 304.922866 289.320298 \n",
       "L 306.996324 289.347216 \n",
       "L 309.002897 289.71555 \n",
       "L 311.076355 287.003479 \n",
       "L 313.149814 283.870937 \n",
       "L 315.156386 285.070953 \n",
       "L 317.229845 287.288249 \n",
       "L 319.236418 284.621792 \n",
       "L 321.309876 285.514863 \n",
       "L 323.383334 285.513143 \n",
       "L 325.256136 283.22273 \n",
       "L 327.329594 282.573267 \n",
       "L 329.336167 283.143679 \n",
       "L 331.409625 283.376898 \n",
       "L 333.416198 283.096896 \n",
       "L 335.489656 281.97918 \n",
       "L 337.563115 281.15267 \n",
       "L 339.569688 282.241876 \n",
       "L 341.643146 282.152687 \n",
       "L 343.649719 281.824621 \n",
       "L 345.723177 285.547561 \n",
       "L 347.796636 286.586436 \n",
       "L 349.736323 283.412132 \n",
       "L 351.809781 283.583674 \n",
       "L 353.816354 282.085275 \n",
       "L 355.889812 281.808322 \n",
       "L 357.896385 282.800806 \n",
       "L 359.969843 285.143674 \n",
       "L 362.043302 281.590087 \n",
       "L 364.049875 282.900668 \n",
       "L 366.123333 282.048386 \n",
       "L 368.129906 284.616307 \n",
       "L 370.203364 284.152509 \n",
       "L 372.276823 282.985263 \n",
       "L 374.149624 281.379391 \n",
       "L 376.223082 280.521829 \n",
       "L 378.229655 281.018742 \n",
       "L 380.303114 277.468306 \n",
       "L 382.309686 279.135046 \n",
       "L 384.383145 277.007435 \n",
       "L 386.456603 274.127176 \n",
       "L 388.463176 274.808634 \n",
       "L 390.536634 273.416326 \n",
       "L 392.543207 270.799276 \n",
       "L 394.616666 269.324746 \n",
       "L 396.690124 266.939248 \n",
       "L 398.562925 263.555217 \n",
       "L 400.636384 261.935337 \n",
       "L 402.642956 263.127257 \n",
       "L 404.716415 262.115824 \n",
       "L 406.722987 260.061518 \n",
       "L 408.796446 258.777474 \n",
       "L 410.869904 256.375281 \n",
       "L 412.876477 251.910852 \n",
       "L 414.949936 251.273336 \n",
       "L 416.956508 253.091024 \n",
       "L 419.029967 269.894527 \n",
       "L 421.103425 264.356767 \n",
       "L 422.976226 263.339626 \n",
       "L 425.049685 256.723175 \n",
       "L 427.056258 257.393718 \n",
       "L 429.129716 243.480057 \n",
       "L 431.136289 245.294577 \n",
       "L 433.209747 248.802083 \n",
       "L 435.283206 247.968645 \n",
       "L 437.289778 244.810125 \n",
       "L 439.363237 237.095114 \n",
       "L 441.36981 228.301421 \n",
       "L 443.443268 222.926224 \n",
       "L 445.516726 227.880177 \n",
       "L 447.456413 228.124859 \n",
       "L 449.529872 221.440053 \n",
       "L 451.536445 218.870843 \n",
       "L 453.609903 219.703863 \n",
       "L 455.616476 213.992749 \n",
       "L 457.689934 215.264663 \n",
       "L 459.763393 213.863505 \n",
       "L 463.843424 210.374336 \n",
       "L 465.849997 212.563233 \n",
       "L 467.923455 212.511262 \n",
       "L 469.996913 216.939338 \n",
       "L 471.869715 215.212616 \n",
       "L 473.943173 216.130235 \n",
       "L 475.949746 220.670464 \n",
       "L 478.023204 226.905345 \n",
       "L 480.029777 226.833342 \n",
       "L 482.103235 228.502821 \n",
       "L 484.176694 228.796255 \n",
       "L 486.183267 228.134806 \n",
       "L 490.263298 236.714486 \n",
       "L 492.336756 238.987386 \n",
       "L 494.410215 244.59092 \n",
       "L 496.283016 244.785826 \n",
       "L 498.356474 240.821751 \n",
       "L 500.363047 242.315177 \n",
       "L 502.436505 244.620886 \n",
       "L 504.443078 248.352825 \n",
       "L 506.516537 247.96564 \n",
       "L 508.589995 250.067002 \n",
       "L 510.596568 252.894445 \n",
       "L 512.670026 253.535557 \n",
       "L 514.676599 248.821818 \n",
       "L 516.750057 249.469315 \n",
       "L 518.823516 254.287796 \n",
       "L 520.696317 249.281058 \n",
       "L 522.769776 245.35504 \n",
       "L 524.776348 247.684413 \n",
       "L 526.849807 246.199503 \n",
       "L 528.856379 249.441783 \n",
       "L 530.929838 252.270903 \n",
       "L 533.003296 253.747794 \n",
       "L 535.009869 252.861221 \n",
       "L 537.083328 254.838859 \n",
       "L 539.0899 255.881216 \n",
       "L 541.163359 254.866686 \n",
       "L 545.176504 255.19719 \n",
       "L 547.249963 252.079346 \n",
       "L 549.256535 256.15118 \n",
       "L 551.329994 254.953501 \n",
       "L 553.336566 257.580312 \n",
       "L 555.410025 257.398788 \n",
       "L 557.483483 255.264373 \n",
       "L 559.490056 257.20502 \n",
       "L 561.563514 258.95488 \n",
       "L 563.570087 260.444776 \n",
       "L 567.717004 275.724433 \n",
       "L 569.589805 272.141853 \n",
       "L 571.663264 267.832016 \n",
       "L 573.669836 270.344293 \n",
       "L 575.743295 269.898434 \n",
       "L 577.749868 268.753518 \n",
       "L 579.823326 264.959857 \n",
       "L 581.896785 261.802332 \n",
       "L 583.903357 262.382691 \n",
       "L 585.976816 265.3944 \n",
       "L 587.983388 256.608088 \n",
       "L 590.056847 252.84639 \n",
       "L 592.130305 253.059629 \n",
       "L 594.003107 250.103034 \n",
       "L 596.076565 246.04369 \n",
       "L 598.083138 254.131739 \n",
       "L 600.156596 248.720163 \n",
       "L 602.163169 250.837694 \n",
       "L 604.236627 244.334997 \n",
       "L 606.310086 245.128082 \n",
       "L 608.316659 247.649627 \n",
       "L 610.390117 240.594526 \n",
       "L 612.39669 239.849939 \n",
       "L 614.470148 241.963867 \n",
       "L 616.543607 240.589944 \n",
       "L 618.416408 236.412926 \n",
       "L 620.489866 238.413557 \n",
       "L 622.496439 241.237629 \n",
       "L 624.569897 237.523527 \n",
       "L 626.57647 235.216067 \n",
       "L 628.649929 237.28415 \n",
       "L 630.723387 236.156502 \n",
       "L 632.72996 234.455815 \n",
       "L 634.803418 232.895193 \n",
       "L 636.809991 228.040563 \n",
       "L 638.883449 228.15434 \n",
       "L 640.956908 236.946314 \n",
       "L 642.896595 242.614196 \n",
       "L 644.970053 237.994789 \n",
       "L 646.976626 241.203316 \n",
       "L 649.050084 241.266358 \n",
       "L 651.056657 246.725968 \n",
       "L 653.130116 246.743425 \n",
       "L 655.203574 246.241938 \n",
       "L 657.210147 244.403341 \n",
       "L 659.283605 238.659396 \n",
       "L 661.290178 233.624807 \n",
       "L 663.363636 235.430609 \n",
       "L 663.363636 235.430609 \n",
       "\" clip-path=\"url(#p60abc391f2)\" style=\"fill: none; stroke: #ff0000; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_34\">\n",
       "    <path d=\"M 54.636364 323.416406 \n",
       "L 56.576051 324.72 \n",
       "L 58.649509 324.642502 \n",
       "L 62.72954 323.980614 \n",
       "L 64.736113 322.555254 \n",
       "L 66.809571 321.777248 \n",
       "L 68.88303 322.618036 \n",
       "L 70.889603 323.196185 \n",
       "L 72.963061 323.100246 \n",
       "L 77.043092 322.227846 \n",
       "L 80.989352 320.56727 \n",
       "L 83.06281 320.861151 \n",
       "L 85.069383 321.492415 \n",
       "L 87.142841 322.280525 \n",
       "L 89.149414 321.705564 \n",
       "L 93.296331 321.951279 \n",
       "L 95.302904 321.314711 \n",
       "L 97.376362 321.044646 \n",
       "L 99.382935 320.636994 \n",
       "L 101.456393 319.930507 \n",
       "L 103.529852 319.663328 \n",
       "L 105.402653 319.290208 \n",
       "L 109.482684 319.67863 \n",
       "L 111.556143 320.261659 \n",
       "L 113.562715 319.561364 \n",
       "L 115.636174 319.676022 \n",
       "L 117.709632 319.313756 \n",
       "L 119.716205 319.229044 \n",
       "L 121.789663 319.357352 \n",
       "L 123.796236 318.983619 \n",
       "L 125.869695 318.86907 \n",
       "L 127.943153 318.367889 \n",
       "L 129.815954 318.458517 \n",
       "L 131.889413 317.785515 \n",
       "L 133.895985 316.485203 \n",
       "L 135.969444 316.614717 \n",
       "L 137.976017 315.653241 \n",
       "L 140.049475 314.906353 \n",
       "L 142.122934 315.034576 \n",
       "L 144.129506 314.929434 \n",
       "L 146.202965 312.204182 \n",
       "L 148.209537 311.911791 \n",
       "L 150.282996 308.613737 \n",
       "L 152.356454 308.863462 \n",
       "L 154.296141 309.321139 \n",
       "L 156.3696 308.346428 \n",
       "L 158.376172 306.240099 \n",
       "L 160.449631 306.566631 \n",
       "L 162.456204 304.755008 \n",
       "L 164.529662 304.090595 \n",
       "L 166.603121 302.222213 \n",
       "L 170.683152 299.64808 \n",
       "L 172.689724 301.191296 \n",
       "L 174.763183 299.064482 \n",
       "L 176.836641 297.983706 \n",
       "L 178.709443 296.815459 \n",
       "L 180.782901 294.717609 \n",
       "L 182.789474 291.8934 \n",
       "L 184.862932 294.744867 \n",
       "L 186.869505 292.355555 \n",
       "L 188.942963 288.728421 \n",
       "L 191.016422 290.473197 \n",
       "L 193.022994 289.511147 \n",
       "L 195.096453 289.06584 \n",
       "L 197.103026 289.703777 \n",
       "L 199.176484 287.346582 \n",
       "L 201.249943 286.914864 \n",
       "L 203.122744 286.941914 \n",
       "L 205.196202 286.364289 \n",
       "L 207.202775 286.123957 \n",
       "L 209.276233 288.837209 \n",
       "L 211.282806 287.000384 \n",
       "L 213.356265 287.385742 \n",
       "L 215.429723 288.071042 \n",
       "L 217.436296 289.035646 \n",
       "L 219.509754 285.01609 \n",
       "L 221.516327 280.472991 \n",
       "L 223.589785 278.114171 \n",
       "L 225.663244 278.904717 \n",
       "L 227.536045 281.025498 \n",
       "L 229.609503 282.121883 \n",
       "L 231.616076 287.85181 \n",
       "L 233.689535 286.054061 \n",
       "L 235.696107 278.79975 \n",
       "L 237.769566 278.480785 \n",
       "L 239.843024 275.09075 \n",
       "L 241.849597 271.158038 \n",
       "L 243.923055 263.937774 \n",
       "L 245.929628 263.653821 \n",
       "L 248.003087 266.060893 \n",
       "L 252.016232 266.956069 \n",
       "L 254.08969 266.91151 \n",
       "L 256.096263 259.567184 \n",
       "L 258.169722 261.912155 \n",
       "L 260.176294 260.780123 \n",
       "L 262.249753 260.623459 \n",
       "L 264.323211 253.901594 \n",
       "L 266.329784 256.586917 \n",
       "L 268.403242 252.563296 \n",
       "L 270.409815 249.387327 \n",
       "L 272.483274 249.821384 \n",
       "L 274.556732 245.173575 \n",
       "L 276.429533 248.550962 \n",
       "L 278.502992 250.027682 \n",
       "L 280.509564 247.308333 \n",
       "L 282.583023 247.278041 \n",
       "L 284.589596 244.860201 \n",
       "L 286.663054 251.772258 \n",
       "L 288.736512 249.519483 \n",
       "L 290.743085 245.978522 \n",
       "L 292.816544 247.237629 \n",
       "L 294.823116 249.359272 \n",
       "L 298.970033 245.077012 \n",
       "L 300.842834 247.706718 \n",
       "L 302.916293 247.580407 \n",
       "L 304.922866 247.201464 \n",
       "L 306.996324 246.572435 \n",
       "L 309.002897 243.015316 \n",
       "L 311.076355 243.426665 \n",
       "L 313.149814 248.77844 \n",
       "L 315.156386 252.59672 \n",
       "L 317.229845 252.122395 \n",
       "L 319.236418 252.7826 \n",
       "L 321.309876 249.609786 \n",
       "L 323.383334 245.180016 \n",
       "L 325.256136 250.841155 \n",
       "L 329.336167 245.84017 \n",
       "L 331.409625 244.707905 \n",
       "L 333.416198 244.642271 \n",
       "L 335.489656 246.50232 \n",
       "L 337.563115 245.337781 \n",
       "L 339.569688 241.151 \n",
       "L 341.643146 239.942696 \n",
       "L 343.649719 241.147397 \n",
       "L 345.723177 230.74819 \n",
       "L 347.796636 226.331954 \n",
       "L 349.736323 229.74442 \n",
       "L 351.809781 227.788314 \n",
       "L 353.816354 226.972749 \n",
       "L 355.889812 228.151244 \n",
       "L 359.969843 220.020819 \n",
       "L 362.043302 221.041919 \n",
       "L 364.049875 220.760391 \n",
       "L 366.123333 219.941613 \n",
       "L 368.129906 213.429888 \n",
       "L 370.203364 213.591665 \n",
       "L 372.276823 214.202536 \n",
       "L 374.149624 215.877453 \n",
       "L 376.223082 217.060118 \n",
       "L 378.229655 215.061387 \n",
       "L 380.303114 220.492084 \n",
       "L 382.309686 216.574421 \n",
       "L 384.383145 220.455894 \n",
       "L 386.456603 219.81 \n",
       "L 388.463176 223.118289 \n",
       "L 390.536634 216.59666 \n",
       "L 392.543207 220.272227 \n",
       "L 394.616666 215.656005 \n",
       "L 396.690124 223.925517 \n",
       "L 398.562925 225.091383 \n",
       "L 400.636384 218.298975 \n",
       "L 402.642956 215.772001 \n",
       "L 404.716415 219.824196 \n",
       "L 406.722987 222.48432 \n",
       "L 408.796446 218.567942 \n",
       "L 410.869904 222.741112 \n",
       "L 412.876477 226.436519 \n",
       "L 414.949936 223.445634 \n",
       "L 416.956508 217.43275 \n",
       "L 419.029967 197.419026 \n",
       "L 421.103425 202.741694 \n",
       "L 422.976226 208.419088 \n",
       "L 425.049685 216.935779 \n",
       "L 427.056258 218.667081 \n",
       "L 429.129716 231.410525 \n",
       "L 433.209747 212.043034 \n",
       "L 435.283206 206.876675 \n",
       "L 437.289778 203.973812 \n",
       "L 439.363237 214.713974 \n",
       "L 441.36981 215.019263 \n",
       "L 443.443268 211.684041 \n",
       "L 445.516726 202.744563 \n",
       "L 447.456413 201.962907 \n",
       "L 449.529872 203.2354 \n",
       "L 451.536445 201.406667 \n",
       "L 453.609903 198.602764 \n",
       "L 455.616476 199.279885 \n",
       "L 457.689934 191.571978 \n",
       "L 459.763393 191.939058 \n",
       "L 461.769965 189.641413 \n",
       "L 463.843424 190.957939 \n",
       "L 465.849997 189.788757 \n",
       "L 467.923455 189.613966 \n",
       "L 469.996913 186.880888 \n",
       "L 471.869715 186.470872 \n",
       "L 473.943173 181.248439 \n",
       "L 475.949746 172.023147 \n",
       "L 478.023204 163.318608 \n",
       "L 480.029777 159.494579 \n",
       "L 482.103235 154.38788 \n",
       "L 484.176694 157.217565 \n",
       "L 486.183267 159.728824 \n",
       "L 488.256725 152.123878 \n",
       "L 490.263298 146.875531 \n",
       "L 492.336756 143.096298 \n",
       "L 494.410215 125.738179 \n",
       "L 496.283016 128.477739 \n",
       "L 498.356474 144.162839 \n",
       "L 500.363047 145.240298 \n",
       "L 502.436505 140.182432 \n",
       "L 506.516537 126.406809 \n",
       "L 508.589995 124.43493 \n",
       "L 510.596568 118.922219 \n",
       "L 512.670026 111.226236 \n",
       "L 514.676599 118.456636 \n",
       "L 516.750057 116.106377 \n",
       "L 518.823516 105.666181 \n",
       "L 520.696317 128.542418 \n",
       "L 522.769776 137.298227 \n",
       "L 524.776348 129.80199 \n",
       "L 526.849807 129.920333 \n",
       "L 528.856379 122.528185 \n",
       "L 530.929838 120.380506 \n",
       "L 533.003296 129.96497 \n",
       "L 535.009869 126.235175 \n",
       "L 537.083328 124.504626 \n",
       "L 539.0899 121.899843 \n",
       "L 541.163359 122.741562 \n",
       "L 543.236817 133.190217 \n",
       "L 545.176504 145.807387 \n",
       "L 547.249963 132.869581 \n",
       "L 549.256535 134.274248 \n",
       "L 551.329994 136.942919 \n",
       "L 553.336566 143.535868 \n",
       "L 555.410025 145.415236 \n",
       "L 557.483483 138.160577 \n",
       "L 559.490056 136.482709 \n",
       "L 561.563514 136.670864 \n",
       "L 563.570087 128.712148 \n",
       "L 565.643546 138.035871 \n",
       "L 567.717004 134.22003 \n",
       "L 569.589805 121.979747 \n",
       "L 571.663264 112.163498 \n",
       "L 573.669836 127.759864 \n",
       "L 575.743295 137.240929 \n",
       "L 577.749868 148.473591 \n",
       "L 579.823326 157.855796 \n",
       "L 581.896785 149.516005 \n",
       "L 583.903357 138.440633 \n",
       "L 585.976816 147.460816 \n",
       "L 587.983388 154.981097 \n",
       "L 590.056847 144.136939 \n",
       "L 592.130305 132.072957 \n",
       "L 594.003107 130.486415 \n",
       "L 596.076565 122.384459 \n",
       "L 598.083138 106.615928 \n",
       "L 600.156596 114.995525 \n",
       "L 602.163169 120.665992 \n",
       "L 604.236627 124.91239 \n",
       "L 608.316659 110.998048 \n",
       "L 610.390117 121.290062 \n",
       "L 612.39669 114.231674 \n",
       "L 614.470148 113.571479 \n",
       "L 616.543607 110.097952 \n",
       "L 618.416408 108.980776 \n",
       "L 620.489866 112.092712 \n",
       "L 622.496439 100.758182 \n",
       "L 624.569897 102.272548 \n",
       "L 626.57647 97.611911 \n",
       "L 628.649929 90.197671 \n",
       "L 630.723387 88.21262 \n",
       "L 632.72996 85.286687 \n",
       "L 634.803418 94.138718 \n",
       "L 636.809991 97.433942 \n",
       "L 638.883449 92.004403 \n",
       "L 640.956908 61.482904 \n",
       "L 642.896595 65.626876 \n",
       "L 644.970053 61.177722 \n",
       "L 646.976626 44.278392 \n",
       "L 649.050084 33.858251 \n",
       "L 651.056657 22.32 \n",
       "L 653.130116 31.508608 \n",
       "L 655.203574 25.586186 \n",
       "L 657.210147 48.704561 \n",
       "L 659.283605 89.656806 \n",
       "L 661.290178 84.886136 \n",
       "L 663.363636 62.648767 \n",
       "L 663.363636 62.648767 \n",
       "\" clip-path=\"url(#p60abc391f2)\" style=\"fill: none; stroke: #0000ff; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 24.2 339.84 \n",
       "L 24.2 7.2 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 693.8 339.84 \n",
       "L 693.8 7.2 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 24.2 339.84 \n",
       "L 693.8 339.84 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path d=\"M 24.2 7.2 \n",
       "L 693.8 7.2 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"legend_1\">\n",
       "    <g id=\"patch_7\">\n",
       "     <path d=\"M 31.2 41.7 \n",
       "L 78.2 41.7 \n",
       "Q 80.2 41.7 80.2 39.7 \n",
       "L 80.2 14.2 \n",
       "Q 80.2 12.2 78.2 12.2 \n",
       "L 31.2 12.2 \n",
       "Q 29.2 12.2 29.2 14.2 \n",
       "L 29.2 39.7 \n",
       "Q 29.2 41.7 31.2 41.7 \n",
       "z\n",
       "\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n",
       "    </g>\n",
       "    <g id=\"line2d_35\">\n",
       "     <path d=\"M 33.2 19.7 \n",
       "L 43.2 19.7 \n",
       "L 53.2 19.7 \n",
       "\" style=\"fill: none; stroke: #ff0000; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "    </g>\n",
       "    <g id=\"text_33\">\n",
       "     <!-- SMB -->\n",
       "     <g transform=\"translate(61.2 23.2) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"SimHei-53\" d=\"M 2900 1325 \n",
       "Q 2900 750 2537 412 \n",
       "Q 2175 75 1550 75 \n",
       "Q 925 75 575 425 \n",
       "Q 225 775 225 1300 \n",
       "L 225 1475 \n",
       "L 800 1475 \n",
       "L 800 1325 \n",
       "Q 800 950 1025 750 \n",
       "Q 1250 550 1550 550 \n",
       "Q 1950 550 2137 762 \n",
       "Q 2325 975 2325 1275 \n",
       "Q 2325 1525 2100 1737 \n",
       "Q 1875 1950 1450 2125 \n",
       "Q 850 2350 587 2625 \n",
       "Q 325 2900 325 3275 \n",
       "Q 325 3800 687 4125 \n",
       "Q 1050 4450 1550 4450 \n",
       "Q 2200 4450 2487 4062 \n",
       "Q 2775 3675 2775 3225 \n",
       "L 2200 3225 \n",
       "Q 2225 3500 2050 3725 \n",
       "Q 1875 3950 1550 3950 \n",
       "Q 1250 3950 1075 3787 \n",
       "Q 900 3625 900 3350 \n",
       "Q 900 3125 1037 2962 \n",
       "Q 1175 2800 1750 2575 \n",
       "Q 2300 2350 2600 2037 \n",
       "Q 2900 1725 2900 1325 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"SimHei-4d\" d=\"M 2925 125 \n",
       "L 2425 125 \n",
       "L 2425 3175 \n",
       "L 2375 3175 \n",
       "L 1775 125 \n",
       "L 1375 125 \n",
       "L 775 3175 \n",
       "L 725 3175 \n",
       "L 725 125 \n",
       "L 225 125 \n",
       "L 225 4400 \n",
       "L 1000 4400 \n",
       "L 1550 1575 \n",
       "L 1600 1575 \n",
       "L 2150 4400 \n",
       "L 2925 4400 \n",
       "L 2925 125 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"SimHei-42\" d=\"M 2950 1400 \n",
       "Q 2950 675 2550 400 \n",
       "Q 2150 125 1525 125 \n",
       "L 275 125 \n",
       "L 275 4400 \n",
       "L 1575 4400 \n",
       "Q 2200 4400 2512 4075 \n",
       "Q 2825 3750 2825 3300 \n",
       "Q 2825 2850 2612 2637 \n",
       "Q 2400 2425 2175 2350 \n",
       "Q 2475 2275 2712 2037 \n",
       "Q 2950 1800 2950 1400 \n",
       "z\n",
       "M 2250 3300 \n",
       "Q 2250 3625 2062 3775 \n",
       "Q 1875 3925 1600 3925 \n",
       "L 850 3925 \n",
       "L 850 2600 \n",
       "L 1575 2600 \n",
       "Q 1850 2600 2050 2762 \n",
       "Q 2250 2925 2250 3300 \n",
       "z\n",
       "M 2350 1400 \n",
       "Q 2350 1800 2087 1962 \n",
       "Q 1825 2125 1500 2125 \n",
       "L 850 2125 \n",
       "L 850 600 \n",
       "L 1425 600 \n",
       "Q 1875 600 2112 775 \n",
       "Q 2350 950 2350 1400 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#SimHei-53\"/>\n",
       "      <use xlink:href=\"#SimHei-4d\" x=\"50\"/>\n",
       "      <use xlink:href=\"#SimHei-42\" x=\"100\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_36\">\n",
       "     <path d=\"M 33.2 32.95 \n",
       "L 43.2 32.95 \n",
       "L 53.2 32.95 \n",
       "\" style=\"fill: none; stroke: #0000ff; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "    </g>\n",
       "    <g id=\"text_34\">\n",
       "     <!-- HML -->\n",
       "     <g transform=\"translate(61.2 36.45) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"SimHei-48\" d=\"M 2850 125 \n",
       "L 2275 125 \n",
       "L 2275 2125 \n",
       "L 850 2125 \n",
       "L 850 125 \n",
       "L 275 125 \n",
       "L 275 4400 \n",
       "L 850 4400 \n",
       "L 850 2600 \n",
       "L 2275 2600 \n",
       "L 2275 4400 \n",
       "L 2850 4400 \n",
       "L 2850 125 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"SimHei-4c\" d=\"M 2900 125 \n",
       "L 300 125 \n",
       "L 300 4400 \n",
       "L 875 4400 \n",
       "L 875 600 \n",
       "L 2900 600 \n",
       "L 2900 125 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#SimHei-48\"/>\n",
       "      <use xlink:href=\"#SimHei-4d\" x=\"50\"/>\n",
       "      <use xlink:href=\"#SimHei-4c\" x=\"100\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p60abc391f2\">\n",
       "   <rect x=\"24.2\" y=\"7.2\" width=\"669.6\" height=\"332.64\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<Figure size 1200x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(12,6))\n",
    "\n",
    "factors['SMBprice'] = (factors['SMB'] + 1).cumprod()\n",
    "factors['HMLprice'] = (factors['HML'] + 1).cumprod()\n",
    "\n",
    "plt.plot(factors['SMBprice'],color='red',label='SMB')\n",
    "plt.plot(factors['HMLprice'],color='blue',label='HML')\n",
    "plt.legend(loc='upper left')\n",
    "\n",
    "xticks = factors.index[::12]\n",
    "xtick_labels = [label.year for label in xticks]\n",
    "plt.xticks(xticks, xtick_labels, rotation=90)\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cd43564d",
   "metadata": {},
   "source": [
    "最大回测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "4a1b5902",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum Drawdown: -0.48398211660103563\n"
     ]
    }
   ],
   "source": [
    "# 计算累积收益率\n",
    "factors['cumulative_return'] = (1 + factors['SMB']).cumprod()\n",
    "\n",
    "# 计算滚动最大值\n",
    "factors['rolling_max'] = factors['cumulative_return'].cummax()\n",
    "\n",
    "# 计算回撤\n",
    "factors['drawdown'] = factors['cumulative_return'] / factors['rolling_max'] - 1\n",
    "\n",
    "# 计算最大回撤\n",
    "max_drawdown = factors['drawdown'].min()\n",
    "print(f\"Maximum Drawdown: {max_drawdown}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "7f19e2d0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum Drawdown: -0.48398211660103563\n",
      "Maximum Drawdown Start Date: 2016-10-31 00:00:00\n",
      "Maximum Drawdown End Date: 2021-01-31 00:00:00\n"
     ]
    }
   ],
   "source": [
    "# 找出最大回撤的时间\n",
    "max_drawdown_end = factors['drawdown'].idxmin() # 返回 Series 中最小值的索引\n",
    "max_drawdown_start = factors.loc[:max_drawdown_end, 'cumulative_return'].idxmax() # 这部分代码选择了从数据开始到 max_drawdown_end 时间点之间的所有累积收益率\n",
    "\n",
    "print(f\"Maximum Drawdown: {max_drawdown}\")\n",
    "print(f\"Maximum Drawdown Start Date: {max_drawdown_start}\")\n",
    "print(f\"Maximum Drawdown End Date: {max_drawdown_end}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "d859b48a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum Drawdown: -0.2297015303495128\n"
     ]
    }
   ],
   "source": [
    "# 计算累积收益率\n",
    "factors['cumulative_return'] = (1 + factors['HML']).cumprod()\n",
    "\n",
    "# 计算滚动最大值\n",
    "factors['rolling_max'] = factors['cumulative_return'].cummax()\n",
    "\n",
    "# 计算回撤\n",
    "factors['drawdown'] = factors['cumulative_return'] / factors['rolling_max'] - 1\n",
    "\n",
    "# 计算最大回撤\n",
    "max_drawdown = factors['drawdown'].min()\n",
    "print(f\"Maximum Drawdown: {max_drawdown}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "7ee1b78b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum Drawdown: -0.2297015303495128\n",
      "Maximum Drawdown Start Date: 2014-12-31 00:00:00\n",
      "Maximum Drawdown End Date: 2015-05-31 00:00:00\n"
     ]
    }
   ],
   "source": [
    "# 找出最大回撤的时间\n",
    "max_drawdown_end = factors['drawdown'].idxmin() # 返回 Series 中最小值的索引\n",
    "max_drawdown_start = factors.loc[:max_drawdown_end, 'cumulative_return'].idxmax() # 这部分代码选择了从数据开始到 max_drawdown_end 时间点之间的所有累积收益率\n",
    "\n",
    "print(f\"Maximum Drawdown: {max_drawdown}\")\n",
    "print(f\"Maximum Drawdown Start Date: {max_drawdown_start}\")\n",
    "print(f\"Maximum Drawdown End Date: {max_drawdown_end}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ab0c56d",
   "metadata": {},
   "source": [
    "Explain Size Effect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "e4dfd6c8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "十分组投资组合描述统计:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>P1</th>\n",
       "      <th>P2</th>\n",
       "      <th>P3</th>\n",
       "      <th>P4</th>\n",
       "      <th>P5</th>\n",
       "      <th>P6</th>\n",
       "      <th>P7</th>\n",
       "      <th>P8</th>\n",
       "      <th>P9</th>\n",
       "      <th>P10</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.010564</td>\n",
       "      <td>0.007316</td>\n",
       "      <td>0.005441</td>\n",
       "      <td>0.005200</td>\n",
       "      <td>0.003357</td>\n",
       "      <td>0.004509</td>\n",
       "      <td>0.004163</td>\n",
       "      <td>0.001811</td>\n",
       "      <td>0.002753</td>\n",
       "      <td>0.002225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.086971</td>\n",
       "      <td>0.084650</td>\n",
       "      <td>0.083982</td>\n",
       "      <td>0.084101</td>\n",
       "      <td>0.081135</td>\n",
       "      <td>0.080800</td>\n",
       "      <td>0.077173</td>\n",
       "      <td>0.074590</td>\n",
       "      <td>0.070466</td>\n",
       "      <td>0.058852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-0.314421</td>\n",
       "      <td>-0.314130</td>\n",
       "      <td>-0.308836</td>\n",
       "      <td>-0.314012</td>\n",
       "      <td>-0.313402</td>\n",
       "      <td>-0.297510</td>\n",
       "      <td>-0.301322</td>\n",
       "      <td>-0.311698</td>\n",
       "      <td>-0.276763</td>\n",
       "      <td>-0.198962</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>-0.036328</td>\n",
       "      <td>-0.036560</td>\n",
       "      <td>-0.038424</td>\n",
       "      <td>-0.038278</td>\n",
       "      <td>-0.041325</td>\n",
       "      <td>-0.040227</td>\n",
       "      <td>-0.033334</td>\n",
       "      <td>-0.037525</td>\n",
       "      <td>-0.034747</td>\n",
       "      <td>-0.034001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.005077</td>\n",
       "      <td>0.000185</td>\n",
       "      <td>0.000294</td>\n",
       "      <td>0.003282</td>\n",
       "      <td>0.000565</td>\n",
       "      <td>0.002452</td>\n",
       "      <td>0.003103</td>\n",
       "      <td>0.003071</td>\n",
       "      <td>0.000487</td>\n",
       "      <td>0.000922</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.058430</td>\n",
       "      <td>0.054609</td>\n",
       "      <td>0.049909</td>\n",
       "      <td>0.046410</td>\n",
       "      <td>0.045516</td>\n",
       "      <td>0.040432</td>\n",
       "      <td>0.040356</td>\n",
       "      <td>0.038633</td>\n",
       "      <td>0.033780</td>\n",
       "      <td>0.028963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>0.313362</td>\n",
       "      <td>0.266499</td>\n",
       "      <td>0.259138</td>\n",
       "      <td>0.250861</td>\n",
       "      <td>0.241643</td>\n",
       "      <td>0.249008</td>\n",
       "      <td>0.228411</td>\n",
       "      <td>0.230366</td>\n",
       "      <td>0.229872</td>\n",
       "      <td>0.287096</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               P1          P2          P3          P4          P5          P6  \\\n",
       "count  180.000000  180.000000  180.000000  180.000000  180.000000  180.000000   \n",
       "mean     0.010564    0.007316    0.005441    0.005200    0.003357    0.004509   \n",
       "std      0.086971    0.084650    0.083982    0.084101    0.081135    0.080800   \n",
       "min     -0.314421   -0.314130   -0.308836   -0.314012   -0.313402   -0.297510   \n",
       "25%     -0.036328   -0.036560   -0.038424   -0.038278   -0.041325   -0.040227   \n",
       "50%      0.005077    0.000185    0.000294    0.003282    0.000565    0.002452   \n",
       "75%      0.058430    0.054609    0.049909    0.046410    0.045516    0.040432   \n",
       "max      0.313362    0.266499    0.259138    0.250861    0.241643    0.249008   \n",
       "\n",
       "               P7          P8          P9         P10  \n",
       "count  180.000000  180.000000  180.000000  180.000000  \n",
       "mean     0.004163    0.001811    0.002753    0.002225  \n",
       "std      0.077173    0.074590    0.070466    0.058852  \n",
       "min     -0.301322   -0.311698   -0.276763   -0.198962  \n",
       "25%     -0.033334   -0.037525   -0.034747   -0.034001  \n",
       "50%      0.003103    0.003071    0.000487    0.000922  \n",
       "75%      0.040356    0.038633    0.033780    0.028963  \n",
       "max      0.228411    0.230366    0.229872    0.287096  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 构造totalvalue十分组投资策略\n",
    "def calc_decile_portfolios(data):\n",
    "    \"\"\"\n",
    "    根据totalvalue构造十分组投资组合\n",
    "    \"\"\"\n",
    "    portfolios = {}\n",
    "    \n",
    "    # 为每个月的每只股票分配十分组标签\n",
    "    def assign_decile(group):\n",
    "        # 计算十分位数\n",
    "        quantiles = [group['totalvalue'].quantile(i/10) for i in range(11)]\n",
    "        # 分配到相应的十分组\n",
    "        labels = pd.cut(group['totalvalue'], bins=quantiles, labels=False,duplicates='drop')\n",
    "        return labels\n",
    "    \n",
    "    data_copy = data.copy()\n",
    "    data_copy['decile'] = data_copy.groupby('month', group_keys=False).apply(\n",
    "        lambda x: assign_decile(x)\n",
    "    )\n",
    "    \n",
    "    # 计算每个十分组的加权收益率\n",
    "    for i in range(10):\n",
    "        decile_name = f'P{i+1}'\n",
    "        portfolios[decile_name] = (\n",
    "            data_copy[data_copy['decile'] == i]\n",
    "            .groupby('month')\n",
    "            .apply(lambda x: np.average(x['next_ret'], weights=x['totalvalue']))\n",
    "            .to_frame(name=decile_name)\n",
    "        )\n",
    "    \n",
    "    return pd.concat(portfolios.values(), axis=1)\n",
    "\n",
    "# 计算十分组投资组合\n",
    "decile_portfolios = calc_decile_portfolios(cross_new)\n",
    "# 调整索引：投资组合收益率应该对应下一个月\n",
    "decile_portfolios.index = decile_portfolios.index + MonthEnd(1)\n",
    "decile_portfolios = decile_portfolios['2010-01':]\n",
    "\n",
    "print(\"十分组投资组合描述统计:\")\n",
    "decile_portfolios.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "c3a0317a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:         size_portfolio   R-squared:                       0.000\n",
      "Model:                            OLS   Adj. R-squared:                  0.000\n",
      "Method:                 Least Squares   F-statistic:                       nan\n",
      "Date:                Mon, 01 Dec 2025   Prob (F-statistic):                nan\n",
      "Time:                        20:45:43   Log-Likelihood:                 217.41\n",
      "No. Observations:                 180   AIC:                            -432.8\n",
      "Df Residuals:                     179   BIC:                            -429.6\n",
      "Df Model:                           0                                         \n",
      "Covariance Type:                  HAC                                         \n",
      "==============================================================================\n",
      "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      0.0083      0.005      1.656      0.098      -0.002       0.018\n",
      "==============================================================================\n",
      "Omnibus:                       34.631   Durbin-Watson:                   1.912\n",
      "Prob(Omnibus):                  0.000   Jarque-Bera (JB):              273.891\n",
      "Skew:                          -0.309   Prob(JB):                     3.35e-60\n",
      "Kurtosis:                       9.011   Cond. No.                         1.00\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 6 lags and without small sample correction\n",
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:         size_portfolio   R-squared:                       0.969\n",
      "Model:                            OLS   Adj. R-squared:                  0.969\n",
      "Method:                 Least Squares   F-statistic:                     431.9\n",
      "Date:                Mon, 01 Dec 2025   Prob (F-statistic):           6.91e-81\n",
      "Time:                        20:45:43   Log-Likelihood:                 530.38\n",
      "No. Observations:                 180   AIC:                            -1053.\n",
      "Df Residuals:                     176   BIC:                            -1040.\n",
      "Df Model:                           3                                         \n",
      "Covariance Type:                  HAC                                         \n",
      "==============================================================================\n",
      "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      0.0035      0.001      3.625      0.000       0.002       0.005\n",
      "MKT            0.0115      0.025      0.460      0.646      -0.037       0.060\n",
      "SMB            1.5068      0.046     32.805      0.000       1.417       1.597\n",
      "HML           -0.4728      0.041    -11.633      0.000      -0.553      -0.393\n",
      "==============================================================================\n",
      "Omnibus:                       12.649   Durbin-Watson:                   1.765\n",
      "Prob(Omnibus):                  0.002   Jarque-Bera (JB):               31.236\n",
      "Skew:                           0.152   Prob(JB):                     1.65e-07\n",
      "Kurtosis:                       5.018   Cond. No.                         37.6\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 6 lags and without small sample correction\n"
     ]
    }
   ],
   "source": [
    "decile_portfolios['size_portfolio'] = decile_portfolios['P1'] - decile_portfolios['P10']\n",
    "decile_portfolios = pd.merge(decile_portfolios, factors, left_index=True, right_index=True, how='left')\n",
    "model_size = smf.ols('size_portfolio ~ 1',\n",
    "                 data=decile_portfolios['2010-01':'2024-12']).fit(\n",
    "                     cov_type='HAC', cov_kwds={'maxlags': 6})\n",
    "print(model_size.summary())\n",
    "model_size_3factors = smf.ols('size_portfolio ~ MKT + SMB + HML',\n",
    "                 data=decile_portfolios['2010-01':'2024-12']).fit(\n",
    "                     cov_type='HAC', cov_kwds={'maxlags': 6})\n",
    "print(model_size_3factors.summary())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b6c79d0",
   "metadata": {},
   "source": [
    "Explain Value Effect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "d8ec0838",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "价值因子十分组投资组合描述统计:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>V1</th>\n",
       "      <th>V2</th>\n",
       "      <th>V3</th>\n",
       "      <th>V4</th>\n",
       "      <th>V5</th>\n",
       "      <th>V6</th>\n",
       "      <th>V7</th>\n",
       "      <th>V8</th>\n",
       "      <th>V9</th>\n",
       "      <th>V10</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>-0.001965</td>\n",
       "      <td>-0.000895</td>\n",
       "      <td>-0.001053</td>\n",
       "      <td>0.003077</td>\n",
       "      <td>0.002132</td>\n",
       "      <td>0.004258</td>\n",
       "      <td>0.003624</td>\n",
       "      <td>0.004091</td>\n",
       "      <td>0.001021</td>\n",
       "      <td>0.004639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.080447</td>\n",
       "      <td>0.084712</td>\n",
       "      <td>0.083200</td>\n",
       "      <td>0.081937</td>\n",
       "      <td>0.079725</td>\n",
       "      <td>0.071735</td>\n",
       "      <td>0.070597</td>\n",
       "      <td>0.067543</td>\n",
       "      <td>0.067503</td>\n",
       "      <td>0.056249</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-0.266041</td>\n",
       "      <td>-0.317027</td>\n",
       "      <td>-0.341337</td>\n",
       "      <td>-0.308362</td>\n",
       "      <td>-0.337108</td>\n",
       "      <td>-0.295875</td>\n",
       "      <td>-0.285445</td>\n",
       "      <td>-0.264207</td>\n",
       "      <td>-0.222903</td>\n",
       "      <td>-0.187168</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>-0.047087</td>\n",
       "      <td>-0.051772</td>\n",
       "      <td>-0.051239</td>\n",
       "      <td>-0.041671</td>\n",
       "      <td>-0.040574</td>\n",
       "      <td>-0.030369</td>\n",
       "      <td>-0.035694</td>\n",
       "      <td>-0.034768</td>\n",
       "      <td>-0.040511</td>\n",
       "      <td>-0.032250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.000989</td>\n",
       "      <td>-0.003199</td>\n",
       "      <td>-0.002615</td>\n",
       "      <td>-0.002322</td>\n",
       "      <td>-0.003701</td>\n",
       "      <td>0.002856</td>\n",
       "      <td>0.004521</td>\n",
       "      <td>0.002228</td>\n",
       "      <td>-0.000151</td>\n",
       "      <td>0.003258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.035849</td>\n",
       "      <td>0.043009</td>\n",
       "      <td>0.046500</td>\n",
       "      <td>0.044212</td>\n",
       "      <td>0.040730</td>\n",
       "      <td>0.039572</td>\n",
       "      <td>0.039646</td>\n",
       "      <td>0.037888</td>\n",
       "      <td>0.030633</td>\n",
       "      <td>0.035654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>0.281034</td>\n",
       "      <td>0.255197</td>\n",
       "      <td>0.237185</td>\n",
       "      <td>0.249976</td>\n",
       "      <td>0.260486</td>\n",
       "      <td>0.230421</td>\n",
       "      <td>0.217674</td>\n",
       "      <td>0.214670</td>\n",
       "      <td>0.213237</td>\n",
       "      <td>0.288665</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               V1          V2          V3          V4          V5          V6  \\\n",
       "count  180.000000  180.000000  180.000000  180.000000  180.000000  180.000000   \n",
       "mean    -0.001965   -0.000895   -0.001053    0.003077    0.002132    0.004258   \n",
       "std      0.080447    0.084712    0.083200    0.081937    0.079725    0.071735   \n",
       "min     -0.266041   -0.317027   -0.341337   -0.308362   -0.337108   -0.295875   \n",
       "25%     -0.047087   -0.051772   -0.051239   -0.041671   -0.040574   -0.030369   \n",
       "50%      0.000989   -0.003199   -0.002615   -0.002322   -0.003701    0.002856   \n",
       "75%      0.035849    0.043009    0.046500    0.044212    0.040730    0.039572   \n",
       "max      0.281034    0.255197    0.237185    0.249976    0.260486    0.230421   \n",
       "\n",
       "               V7          V8          V9         V10  \n",
       "count  180.000000  180.000000  180.000000  180.000000  \n",
       "mean     0.003624    0.004091    0.001021    0.004639  \n",
       "std      0.070597    0.067543    0.067503    0.056249  \n",
       "min     -0.285445   -0.264207   -0.222903   -0.187168  \n",
       "25%     -0.035694   -0.034768   -0.040511   -0.032250  \n",
       "50%      0.004521    0.002228   -0.000151    0.003258  \n",
       "75%      0.039646    0.037888    0.030633    0.035654  \n",
       "max      0.217674    0.214670    0.213237    0.288665  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 构造ep十分组投资策略\n",
    "def calc_value_decile_portfolios(data):\n",
    "    \"\"\"\n",
    "    根据ep构造十分组投资组合\n",
    "    \"\"\"\n",
    "    portfolios = {}\n",
    "    \n",
    "    # 为每个月的每只股票分配十分组标签\n",
    "    def assign_decile(group):\n",
    "        # 计算十分位数\n",
    "        quantiles = [group['ep'].quantile(i/10) for i in range(11)]\n",
    "        # 分配到相应的十分组\n",
    "        labels = pd.cut(group['ep'], bins=quantiles, labels=False,  duplicates='drop')\n",
    "        return labels\n",
    "    \n",
    "    data_copy = data.copy()\n",
    "    data_copy['ep_decile'] = data_copy.groupby('month', group_keys=False).apply(\n",
    "        lambda x: assign_decile(x)\n",
    "    )\n",
    "    \n",
    "    # 计算每个十分组的加权收益率\n",
    "    for i in range(10):\n",
    "        decile_name = f'V{i+1}'\n",
    "        portfolios[decile_name] = (\n",
    "            data_copy[data_copy['ep_decile'] == i]\n",
    "            .groupby('month')\n",
    "            .apply(lambda x: np.average(x['next_ret'], weights=x['totalvalue']))\n",
    "            .to_frame(name=decile_name)\n",
    "        )\n",
    "    \n",
    "    return pd.concat(portfolios.values(), axis=1)\n",
    "\n",
    "# 计算十分组投资组合\n",
    "value_decile_portfolios = calc_value_decile_portfolios(cross_new)\n",
    "# 调整索引：投资组合收益率应该对应下一个月\n",
    "value_decile_portfolios.index = value_decile_portfolios.index + MonthEnd(1)\n",
    "value_decile_portfolios = value_decile_portfolios['2010-01':]\n",
    "\n",
    "print(\"价值因子十分组投资组合描述统计:\")\n",
    "value_decile_portfolios.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "d2ffa853",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:        value_portfolio   R-squared:                      -0.000\n",
      "Model:                            OLS   Adj. R-squared:                 -0.000\n",
      "Method:                 Least Squares   F-statistic:                       nan\n",
      "Date:                Mon, 01 Dec 2025   Prob (F-statistic):                nan\n",
      "Time:                        20:48:13   Log-Likelihood:                 250.47\n",
      "No. Observations:                 180   AIC:                            -498.9\n",
      "Df Residuals:                     179   BIC:                            -495.7\n",
      "Df Model:                           0                                         \n",
      "Covariance Type:                  HAC                                         \n",
      "==============================================================================\n",
      "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      0.0066      0.004      1.778      0.075      -0.001       0.014\n",
      "==============================================================================\n",
      "Omnibus:                       13.992   Durbin-Watson:                   1.779\n",
      "Prob(Omnibus):                  0.001   Jarque-Bera (JB):               40.602\n",
      "Skew:                           0.075   Prob(JB):                     1.53e-09\n",
      "Kurtosis:                       5.322   Cond. No.                         1.00\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 6 lags and without small sample correction\n",
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:        value_portfolio   R-squared:                       0.870\n",
      "Model:                            OLS   Adj. R-squared:                  0.867\n",
      "Method:                 Least Squares   F-statistic:                     176.4\n",
      "Date:                Mon, 01 Dec 2025   Prob (F-statistic):           8.16e-53\n",
      "Time:                        20:48:13   Log-Likelihood:                 433.80\n",
      "No. Observations:                 180   AIC:                            -859.6\n",
      "Df Residuals:                     176   BIC:                            -846.8\n",
      "Df Model:                           3                                         \n",
      "Covariance Type:                  HAC                                         \n",
      "==============================================================================\n",
      "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      0.0027      0.001      2.039      0.041       0.000       0.005\n",
      "MKT           -0.1738      0.050     -3.461      0.001      -0.272      -0.075\n",
      "SMB           -0.4300      0.062     -6.983      0.000      -0.551      -0.309\n",
      "HML            1.0073      0.075     13.472      0.000       0.861       1.154\n",
      "==============================================================================\n",
      "Omnibus:                        2.071   Durbin-Watson:                   2.046\n",
      "Prob(Omnibus):                  0.355   Jarque-Bera (JB):                1.878\n",
      "Skew:                           0.036   Prob(JB):                        0.391\n",
      "Kurtosis:                       3.495   Cond. No.                         37.6\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 6 lags and without small sample correction\n"
     ]
    }
   ],
   "source": [
    "value_decile_portfolios['value_portfolio'] = value_decile_portfolios['V10'] - value_decile_portfolios['V1']\n",
    "value_decile_portfolios = pd.merge(value_decile_portfolios, factors, left_index=True, right_index=True, how='left')\n",
    "model_value = smf.ols('value_portfolio ~ 1',\n",
    "                 data=value_decile_portfolios['2010-01':'2024-12']).fit(\n",
    "                     cov_type='HAC', cov_kwds={'maxlags': 6})\n",
    "print(model_value.summary())\n",
    "model_value_3factors = smf.ols('value_portfolio ~ MKT + SMB + HML',\n",
    "                 data=value_decile_portfolios['2010-01':'2024-12']).fit(\n",
    "                     cov_type='HAC', cov_kwds={'maxlags': 6})\n",
    "print(model_value_3factors.summary())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ce8bcec",
   "metadata": {},
   "source": [
    "Explain Reversal Effect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "4487917c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reversal因子十分组投资组合描述统计:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>R1</th>\n",
       "      <th>R2</th>\n",
       "      <th>R3</th>\n",
       "      <th>R4</th>\n",
       "      <th>R5</th>\n",
       "      <th>R6</th>\n",
       "      <th>R7</th>\n",
       "      <th>R8</th>\n",
       "      <th>R9</th>\n",
       "      <th>R10</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "      <td>180.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.004889</td>\n",
       "      <td>0.004690</td>\n",
       "      <td>0.004492</td>\n",
       "      <td>0.003819</td>\n",
       "      <td>0.004894</td>\n",
       "      <td>0.007326</td>\n",
       "      <td>0.005278</td>\n",
       "      <td>0.003737</td>\n",
       "      <td>0.001548</td>\n",
       "      <td>-0.004750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.082079</td>\n",
       "      <td>0.074105</td>\n",
       "      <td>0.066530</td>\n",
       "      <td>0.067355</td>\n",
       "      <td>0.064517</td>\n",
       "      <td>0.067471</td>\n",
       "      <td>0.063288</td>\n",
       "      <td>0.062088</td>\n",
       "      <td>0.069384</td>\n",
       "      <td>0.082783</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-0.291385</td>\n",
       "      <td>-0.292738</td>\n",
       "      <td>-0.199461</td>\n",
       "      <td>-0.227837</td>\n",
       "      <td>-0.226835</td>\n",
       "      <td>-0.263387</td>\n",
       "      <td>-0.256565</td>\n",
       "      <td>-0.257933</td>\n",
       "      <td>-0.290900</td>\n",
       "      <td>-0.325024</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>-0.043740</td>\n",
       "      <td>-0.034506</td>\n",
       "      <td>-0.035469</td>\n",
       "      <td>-0.035984</td>\n",
       "      <td>-0.035891</td>\n",
       "      <td>-0.029713</td>\n",
       "      <td>-0.028992</td>\n",
       "      <td>-0.032754</td>\n",
       "      <td>-0.037112</td>\n",
       "      <td>-0.053971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.001972</td>\n",
       "      <td>0.000760</td>\n",
       "      <td>-0.000040</td>\n",
       "      <td>0.003015</td>\n",
       "      <td>0.001991</td>\n",
       "      <td>0.005160</td>\n",
       "      <td>0.005717</td>\n",
       "      <td>0.002144</td>\n",
       "      <td>-0.000391</td>\n",
       "      <td>-0.002276</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.041176</td>\n",
       "      <td>0.040624</td>\n",
       "      <td>0.038066</td>\n",
       "      <td>0.034397</td>\n",
       "      <td>0.033612</td>\n",
       "      <td>0.039899</td>\n",
       "      <td>0.037361</td>\n",
       "      <td>0.032024</td>\n",
       "      <td>0.031796</td>\n",
       "      <td>0.039061</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>0.294448</td>\n",
       "      <td>0.249714</td>\n",
       "      <td>0.225407</td>\n",
       "      <td>0.215769</td>\n",
       "      <td>0.229694</td>\n",
       "      <td>0.234607</td>\n",
       "      <td>0.174184</td>\n",
       "      <td>0.194020</td>\n",
       "      <td>0.236972</td>\n",
       "      <td>0.329477</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               R1          R2          R3          R4          R5          R6  \\\n",
       "count  180.000000  180.000000  180.000000  180.000000  180.000000  180.000000   \n",
       "mean     0.004889    0.004690    0.004492    0.003819    0.004894    0.007326   \n",
       "std      0.082079    0.074105    0.066530    0.067355    0.064517    0.067471   \n",
       "min     -0.291385   -0.292738   -0.199461   -0.227837   -0.226835   -0.263387   \n",
       "25%     -0.043740   -0.034506   -0.035469   -0.035984   -0.035891   -0.029713   \n",
       "50%      0.001972    0.000760   -0.000040    0.003015    0.001991    0.005160   \n",
       "75%      0.041176    0.040624    0.038066    0.034397    0.033612    0.039899   \n",
       "max      0.294448    0.249714    0.225407    0.215769    0.229694    0.234607   \n",
       "\n",
       "               R7          R8          R9         R10  \n",
       "count  180.000000  180.000000  180.000000  180.000000  \n",
       "mean     0.005278    0.003737    0.001548   -0.004750  \n",
       "std      0.063288    0.062088    0.069384    0.082783  \n",
       "min     -0.256565   -0.257933   -0.290900   -0.325024  \n",
       "25%     -0.028992   -0.032754   -0.037112   -0.053971  \n",
       "50%      0.005717    0.002144   -0.000391   -0.002276  \n",
       "75%      0.037361    0.032024    0.031796    0.039061  \n",
       "max      0.174184    0.194020    0.236972    0.329477  "
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 构造过去一个月ret十分组投资策略（Reversal效应）\n",
    "def calc_reversal_decile_portfolios(data):\n",
    "    \"\"\"\n",
    "    根据过去一个月的ret构造十分组投资组合\n",
    "    \"\"\"\n",
    "    portfolios = {}\n",
    "    \n",
    "    # 为每个月的每只股票分配十分组标签\n",
    "    def assign_decile(group):\n",
    "        # 计算十分位数\n",
    "        quantiles = [group['ret'].quantile(i/10) for i in range(11)]\n",
    "        # 分配到相应的十分组\n",
    "        labels = pd.cut(group['ret'], bins=quantiles, labels=False, duplicates='drop')\n",
    "        return labels\n",
    "    \n",
    "    data_copy = data.copy()\n",
    "    data_copy['ret_decile'] = data_copy.groupby('month', group_keys=False).apply(\n",
    "        lambda x: assign_decile(x)\n",
    "    )\n",
    "    \n",
    "    # 计算每个十分组的加权收益率\n",
    "    for i in range(10):\n",
    "        decile_name = f'R{i+1}'\n",
    "        portfolios[decile_name] = (\n",
    "            data_copy[data_copy['ret_decile'] == i]\n",
    "            .groupby('month')\n",
    "            .apply(lambda x: np.average(x['next_ret'], weights=x['totalvalue']))\n",
    "            .to_frame(name=decile_name)\n",
    "        )\n",
    "    \n",
    "    return pd.concat(portfolios.values(), axis=1)\n",
    "\n",
    "# 计算十分组投资组合\n",
    "reversal_decile_portfolios = calc_reversal_decile_portfolios(cross_new)\n",
    "# 调整索引：投资组合收益率应该对应下一个月\n",
    "reversal_decile_portfolios.index = reversal_decile_portfolios.index + MonthEnd(1)\n",
    "reversal_decile_portfolios = reversal_decile_portfolios['2010-01':]\n",
    "\n",
    "print(\"Reversal因子十分组投资组合描述统计:\")\n",
    "reversal_decile_portfolios.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "642ac5d3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:     reversal_portfolio   R-squared:                      -0.000\n",
      "Model:                            OLS   Adj. R-squared:                 -0.000\n",
      "Method:                 Least Squares   F-statistic:                       nan\n",
      "Date:                Mon, 01 Dec 2025   Prob (F-statistic):                nan\n",
      "Time:                        20:50:07   Log-Likelihood:                 220.99\n",
      "No. Observations:                 180   AIC:                            -440.0\n",
      "Df Residuals:                     179   BIC:                            -436.8\n",
      "Df Model:                           0                                         \n",
      "Covariance Type:                  HAC                                         \n",
      "==============================================================================\n",
      "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      0.0096      0.005      1.882      0.060      -0.000       0.020\n",
      "==============================================================================\n",
      "Omnibus:                       40.917   Durbin-Watson:                   1.970\n",
      "Prob(Omnibus):                  0.000   Jarque-Bera (JB):              265.744\n",
      "Skew:                          -0.593   Prob(JB):                     1.97e-58\n",
      "Kurtosis:                       8.833   Cond. No.                         1.00\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 6 lags and without small sample correction\n",
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:     reversal_portfolio   R-squared:                       0.121\n",
      "Model:                            OLS   Adj. R-squared:                  0.106\n",
      "Method:                 Least Squares   F-statistic:                     4.598\n",
      "Date:                Mon, 01 Dec 2025   Prob (F-statistic):            0.00400\n",
      "Time:                        20:50:07   Log-Likelihood:                 232.64\n",
      "No. Observations:                 180   AIC:                            -457.3\n",
      "Df Residuals:                     176   BIC:                            -444.5\n",
      "Df Model:                           3                                         \n",
      "Covariance Type:                  HAC                                         \n",
      "==============================================================================\n",
      "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      0.0041      0.004      0.977      0.329      -0.004       0.012\n",
      "MKT           -0.0219      0.191     -0.115      0.909      -0.397       0.353\n",
      "SMB            0.7311      0.262      2.790      0.005       0.218       1.245\n",
      "HML            0.2532      0.220      1.150      0.250      -0.178       0.685\n",
      "==============================================================================\n",
      "Omnibus:                       19.282   Durbin-Watson:                   1.958\n",
      "Prob(Omnibus):                  0.000   Jarque-Bera (JB):               66.027\n",
      "Skew:                          -0.246   Prob(JB):                     4.60e-15\n",
      "Kurtosis:                       5.926   Cond. No.                         37.6\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 6 lags and without small sample correction\n"
     ]
    }
   ],
   "source": [
    "reversal_decile_portfolios['reversal_portfolio'] = reversal_decile_portfolios['R1'] - reversal_decile_portfolios['R10']\n",
    "reversal_decile_portfolios = pd.merge(reversal_decile_portfolios, factors, left_index=True, right_index=True, how='left')\n",
    "model_reversal = smf.ols('reversal_portfolio ~ 1',\n",
    "                 data=reversal_decile_portfolios['2010-01':'2024-12']).fit(\n",
    "                     cov_type='HAC', cov_kwds={'maxlags': 6})\n",
    "print(model_reversal.summary())\n",
    "model_reversal_3factors = smf.ols('reversal_portfolio ~ MKT + SMB + HML',\n",
    "                 data=reversal_decile_portfolios['2010-01':'2024-12']).fit(\n",
    "                     cov_type='HAC', cov_kwds={'maxlags': 6})\n",
    "print(model_reversal_3factors.summary())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
